1
0
mirror of https://github.com/taigrr/godns synced 2025-01-18 04:03:25 -08:00

Support to read parameters from system ENV

This commit is contained in:
Timothy 2016-06-30 17:46:11 +08:00
parent 9787cf537b
commit f04b725ba1
2 changed files with 21 additions and 8 deletions

View File

@ -64,10 +64,26 @@ func main() {
return
}
if err := LoadSettings(*optConf, &configuration); err != nil {
fmt.Println(err.Error())
log.Println(err.Error())
os.Exit(1)
if *optDocker {
//Load settings from ENV
configuration = Settings{
Email: os.Getenv("EMAIL"),
Password: os.Getenv("PASSWORD"),
LoginToken: os.Getenv("TOKEN"),
Domain: os.Getenv("DOMAIN"),
Sub_domain: os.Getenv("SUB_DOMAIN"),
IP_Url: "http://members.3322.org/dyndns/getip",
Log_Path: "./godns.log",
Log_Size: 16,
Log_Num: 3,
}
} else {
//Load settings from configurations file
if err := LoadSettings(*optConf, &configuration); err != nil {
fmt.Println(err.Error())
log.Println(err.Error())
os.Exit(1)
}
}
if err := InitLogger(configuration.Log_Path, configuration.Log_Size, configuration.Log_Num); err != nil {

View File

@ -17,21 +17,18 @@ type Settings struct {
Log_Path string
Log_Size int
Log_Num int
User int
Group int
}
//LoadSettings -- Load settings from config file
func LoadSettings(configPath string, settings *Settings) error {
//LoadSettings from config file
setting := Settings{}
file, err := ioutil.ReadFile(configPath)
if err != nil {
fmt.Println("Error occurs while reading config file, please make sure config file exists!")
return err
}
err = json.Unmarshal(file, &setting)
err = json.Unmarshal(file, settings)
if err != nil {
fmt.Println("Error occurs while unmarshal config file, please make sure config file correct!")
return err