gomail/config.go

46 lines
1013 B
Go

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