2021-07-02 20:09:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config application configuration
|
|
|
|
type Config struct {
|
2021-07-22 00:49:45 +00:00
|
|
|
Addr string `yaml:"addr"`
|
2021-08-24 22:50:29 +00:00
|
|
|
Path string `yaml:"path"`
|
2021-07-22 00:49:45 +00:00
|
|
|
Account []struct {
|
2021-08-29 22:11:59 +00:00
|
|
|
Addr string `yaml:"addr"`
|
2021-07-22 00:49:45 +00:00
|
|
|
Username string `yaml:"username"`
|
|
|
|
Password string `yaml:"password"`
|
|
|
|
}
|
|
|
|
Logger struct {
|
2021-07-02 20:09:38 +00:00
|
|
|
Path string `yaml:"path"`
|
|
|
|
Mode string `yaml:"mode"`
|
|
|
|
Level int `yaml:"level"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig - create new config instance from file path
|
|
|
|
func NewConfig(configFile string) (config *Config) {
|
|
|
|
file, err := ioutil.ReadFile(configFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error loading yaml config file %v", err)
|
|
|
|
}
|
|
|
|
if err = yaml.Unmarshal(file, &config); err != nil {
|
|
|
|
log.Fatalf("Error Unmarshaling yaml config file %v", err)
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFile create new config instance from file
|
|
|
|
func NewFile(configFile []byte) (config *Config) {
|
|
|
|
if err := yaml.Unmarshal(configFile, &config); err != nil {
|
|
|
|
log.Fatalf("Error Unmarshaling yaml config file %v", err)
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|