forked from TimothyYe/godns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.go
More file actions
57 lines (50 loc) · 1.5 KB
/
settings.go
File metadata and controls
57 lines (50 loc) · 1.5 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package godns
import (
"encoding/json"
"fmt"
"io/ioutil"
)
// Domain struct
type Domain struct {
DomainName string `json:"domain_name"`
SubDomains []string `json:"sub_domains"`
}
// Notify struct for SMTP notification
type Notify struct {
Enabled bool `json:"enabled"`
SMTPServer string `json:"smtp_server"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
SMTPPort int `json:"smtp_port"`
SendTo string `json:"send_to"`
}
// Settings struct
type Settings struct {
Provider string `json:"provider"`
Email string `json:"email"`
Password string `json:"password"`
LoginToken string `json:"login_token"`
Domains []Domain `json:"domains"`
IPUrl string `json:"ip_url"`
LogPath string `json:"log_path"`
Socks5Proxy string `json:"socks5_proxy"`
Notify Notify `json:"notify"`
IPInterface string `json:"ip_interface"`
//the code is not ready to update AAAA record
//IPType string `json:"ip_type"`
}
// 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
}