forked from dagedaniao/AutoDnsPodScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
79 lines (71 loc) · 1.83 KB
/
config.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
package main
import (
"errors"
"io/ioutil"
"log"
"encoding/json"
)
type TimeFormat struct {
Hour int `json:"hour"`
Min int `json:"min"`
Sec int `json:"sec"`
}
type Config struct {
ApiToken string `json:"apitoken"`
Ps bool `json:"partlyscale"`
Timely bool `json:"timely"`
ScaleIn bool `json:"scalein"`
StartTime TimeFormat `json:"start-time"`
EndTime TimeFormat `json:"end-time"`
TimeRate int `json:"time-rate"`
}
type RuleCname struct {
Zone string `json:"zone"`
Domain string `json:"domain"`
View string `json:"view"`
From string `json:"from"`
To string `json:"to"`
}
type RuleCnames struct {
Cnames []RuleCname `json:"cnames"`
}
func LoadFile( fileName string) (content []byte, err error) {
if len(fileName) == 0 {
err = errors.New("fileName is empty!!")
log.Printf("fileName is empty", fileName)
return
}
content, err = ioutil.ReadFile(fileName)
if err != nil {
log.Fatal(err)
return
}
return
}
func GetServiceConfig(file string) (config Config, err error) {
content, err := LoadFile(file)
if err != nil {
log.Printf("Config file[%s] \nConfig content: %s", file, content, err)
return
}
err = json.Unmarshal(content, &config)
if err != nil {
log.Println("Service config content:", string(content))
log.Fatal(err)
return
}
return
}
func GetRuleConfig(file string) (config RuleCnames, err error) {
content, err := LoadFile(file)
if err != nil {
log.Printf("Config file[%s] \nConfig content: %s", file, content, err)
return
}
err = json.Unmarshal(content, &config)
if err != nil {
log.Fatal(err)
return
}
return
}