Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
wind8_fetcher/lib/config/config.go

45 lines
1.1 KiB
Go
Raw Normal View History

2017-10-27 07:45:21 +04:00
package config
import (
// stdlib
"io/ioutil"
"path/filepath"
// 3rd-party
"gopkg.in/yaml.v2"
"lab.pztrn.name/golibs/mogrus"
)
// HTTPServerConfiguration handles HTTP server configuration in config file
type HTTPServerConfiguration struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
}
// HTTPClientConfiguration handles HTTP client configuration in config file
type HTTPClientConfiguration struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
Signature string `yaml:"signature"`
}
// Config is a struct which represents config file structure
type Config struct {
HTTPListener HTTPServerConfiguration `yaml:"receiver"`
HTTPSender HTTPClientConfiguration `yaml:"sender"`
}
// Init is a configuration initializer
func (c *Config) Init(log *mogrus.LoggerHandler, configPath string) {
log.Info("Config file path: " + configPath)
fname, _ := filepath.Abs(configPath)
yamlFile, yerr := ioutil.ReadFile(fname)
if yerr != nil {
log.Fatal("Can't read config file")
}
yperr := yaml.Unmarshal(yamlFile, c)
if yperr != nil {
log.Fatal("Can't parse config file")
}
}