-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
68 lines (59 loc) · 1.54 KB
/
init.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
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
)
func init() {
file, err := os.OpenFile("ddns.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
fmt.Println("日志文件初始化失败")
}
log.SetOutput(file)
log.Print("开始动态解析")
}
func init() {
if len(os.Args) == 3 && os.Args[1] == "-c" && len(os.Args[2]) > 0 {
ConfigFile = os.Args[2]
}
}
func init() {
// 读取全局配置
parseConfig(&GlobalConfig)
IPs = GetLocalPubilcIPv6()
log.Println("【获取本地最新 IPv6 公网地址】", IPs)
// 将本地公网 IPv6 地址中的第一个设置为要解析的目标 IP
TargetIP = IPs[0]
// 读取记录值缓存
content, err := ioutil.ReadFile("cache.gnd4")
if err != nil && content != nil {
log.Println("读取缓存失败,将重新获取")
}
for _, cacheValue := range strings.Split(string(content), ",") {
if isLatest := InList(IPs, cacheValue); isLatest {
log.Printf("【获取缓存记录值】记录值 %s 为最新, 无需更新\n", cacheValue)
} else {
log.Println("缓存记录值已失效, 重新获取", cacheValue)
result := &DNSRecordsResult{}
GetDNSRecords(result)
ResourceRecords = result.Reply.ResourceRecords
break
}
}
}
func init() {
content, err := ioutil.ReadFile("error.gnd4")
if err != nil && content != nil {
log.Println("读取错误文件失败")
}
for _, errorRecordId := range strings.Split(string(content), "\n") {
if len(errorRecordId) > 0 {
rr := ResourceRecord{
RecordId: errorRecordId,
}
rr.DeleteDNSRecord()
}
}
}