forked from TimothyYe/godns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
38 lines (33 loc) · 937 Bytes
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
//Settings struct
type Settings struct {
Email string `json:"email"`
Password string `json:"password"`
LoginToken string `json:"login_token"`
Domain string `json:"domain"`
SubDomain string `json:"sub_domain"`
IPUrl string `json:"ip_url"`
LogPath string `json:"log_path"`
LogSize int `json:"log_size"`
LogNum int `json:"log_num"`
}
//LoadSettings -- Load settings from config file
func LoadSettings(configPath string, settings *Settings) error {
//LoadSettings from config file
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, settings)
if err != nil {
fmt.Println("Error occurs while unmarshal config file, please make sure config file correct!")
return err
}
return nil
}