gomail/config.go
Michael 2ba4e0eddc support for multiple emails at once
Signed-off-by: Michael <michael.lindman@gmail.com>
2021-07-22 01:49:45 +01:00

43 lines
962 B
Go

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
}