Archived
1

Initial commit

This commit is contained in:
2017-10-27 07:45:21 +04:00
commit 4672299afb
15 changed files with 791 additions and 0 deletions

44
lib/config/config.go Normal file
View File

@@ -0,0 +1,44 @@
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")
}
}

7
lib/config/exported.go Normal file
View File

@@ -0,0 +1,7 @@
package config
// New creates new empty Config object
func New() *Config {
c := &Config{}
return c
}