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:
parent
9787cf537b
commit
f04b725ba1
24
godns.go
24
godns.go
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user