package main import ( "io/ioutil" "log" "gopkg.in/yaml.v3" ) // Config application configuration type Config struct { Addr string `yaml:"addr"` Account []struct { Username string `yaml:"username"` Password string `yaml:"password"` } Logger struct { 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 }