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
16
godns.go
16
godns.go
@ -64,11 +64,27 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
if err := LoadSettings(*optConf, &configuration); err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := InitLogger(configuration.Log_Path, configuration.Log_Size, configuration.Log_Num); err != nil {
|
if err := InitLogger(configuration.Log_Path, configuration.Log_Size, configuration.Log_Num); err != nil {
|
||||||
log.Println("InitLogger error:", err)
|
log.Println("InitLogger error:", err)
|
||||||
|
@ -17,21 +17,18 @@ type Settings struct {
|
|||||||
Log_Path string
|
Log_Path string
|
||||||
Log_Size int
|
Log_Size int
|
||||||
Log_Num int
|
Log_Num int
|
||||||
User int
|
|
||||||
Group int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//LoadSettings -- Load settings from config file
|
//LoadSettings -- Load settings from config file
|
||||||
func LoadSettings(configPath string, settings *Settings) error {
|
func LoadSettings(configPath string, settings *Settings) error {
|
||||||
//LoadSettings from config file
|
//LoadSettings from config file
|
||||||
setting := Settings{}
|
|
||||||
file, err := ioutil.ReadFile(configPath)
|
file, err := ioutil.ReadFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error occurs while reading config file, please make sure config file exists!")
|
fmt.Println("Error occurs while reading config file, please make sure config file exists!")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(file, &setting)
|
err = json.Unmarshal(file, settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error occurs while unmarshal config file, please make sure config file correct!")
|
fmt.Println("Error occurs while unmarshal config file, please make sure config file correct!")
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user