gomail/config.go
Michael f12e865042 added support for socks5 proxy
Signed-off-by: Michael <michael.lindman@gmail.com>
2021-12-10 04:26:47 +00:00

49 lines
1.1 KiB
Go

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