-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
90 lines (72 loc) · 1.54 KB
/
utils.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"io/ioutil"
"log"
"net"
"gopkg.in/yaml.v2"
)
func GetLocalPubilcIPv6() []string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return nil
}
var ipv6s []string
for _, address := range addrs {
if ipnet, _ := address.(*net.IPNet); ISPublicIPv6(ipnet.IP) {
ipv6s = append(ipv6s, ipnet.IP.String())
}
}
return ipv6s
}
func ISIPv6(ip net.IP) bool {
isIpv6 := ip.To4()
return isIpv6 == nil
}
func ISPublicIPv6(ip net.IP) bool {
return ISIPv6(ip) && ip.IsGlobalUnicast()
}
func InList(list []string, target string) bool {
for _, v := range list {
if target == v {
return true
}
}
return false
}
func parseConfig(config *Config) {
file, err := ioutil.ReadFile(ConfigFile)
if err != nil {
log.Fatal(`读取配置文件 "config.yml" 出错`)
}
err = yaml.Unmarshal(file, config)
if err != nil {
log.Fatal(`解析配置文件 "config.yml" 出错`)
}
if len(config.Key) == 0 {
log.Fatal(`CONFIGERROR: key 不能为空`)
}
if len(config.Domain) == 0 {
log.Fatal(`ConfigError: domain 不能为空`)
}
if len(config.Version) == 0 {
config.Version = "1"
}
if len(config.Type) == 0 {
config.Type = "xml"
}
if len(config.Url.Base) == 0 {
config.Url.Base = "https://www.namesilo.com/api/"
}
if len(config.Url.Get) == 0 {
config.Url.Get = "dnsListRecords"
}
if len(config.Url.Add) == 0 {
config.Url.Add = "dnsAddRecord"
}
if len(config.Url.Update) == 0 {
config.Url.Update = "dnsUpdateRecord"
}
if len(config.Url.Delete) == 0 {
config.Url.Delete = "dnsDeleteRecord"
}
}