-
Notifications
You must be signed in to change notification settings - Fork 22
/
confYaml.go
70 lines (63 loc) · 1.83 KB
/
confYaml.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
package main
import (
"fmt"
"gopkg.in/yaml.v3"
"log"
"os"
"time"
)
var conf struct {
IkuaiURL string `yaml:"ikuai-url"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Cron string `yaml:"cron"`
AddErrRetryWait time.Duration `yaml:"AddErrRetryWait"`
AddWait time.Duration `yaml:"AddWait"`
CustomIsp []struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
Tag string `yaml:"tag"`
} `yaml:"custom-isp"`
StreamDomain []struct {
Interface string `yaml:"interface"`
SrcAddr string `yaml:"src-addr"`
URL string `yaml:"url"`
Tag string `yaml:"tag"`
} `yaml:"stream-domain"`
IpGroup []struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
} `yaml:"ip-group"`
StreamIpPort []struct {
Type string `yaml:"type"`
Interface string `yaml:"interface"`
Nexthop string `yaml:"nexthop"`
SrcAddr string `yaml:"src-addr"`
IpGroup string `yaml:"ip-group"`
} `yaml:"stream-ipport"`
}
func readConf(filename string) error {
buf, err := os.ReadFile(filename)
if err != nil {
return err
}
err = yaml.Unmarshal(buf, &conf)
if err != nil {
return fmt.Errorf("in file %q: %v", filename, err)
}
// 检查每个 CustomIsp 的 Tag,如果不存在,则使用 Name
for i := range conf.CustomIsp {
if conf.CustomIsp[i].Tag == "" {
log.Println("运营商分流规则中配置中Tag为空,采用:", conf.CustomIsp[i].Name)
conf.CustomIsp[i].Tag = conf.CustomIsp[i].Name
}
}
// 检查每个 StreamDomain 的 Tag,如果不存在,则使用 Interface
for i := range conf.StreamDomain {
if conf.StreamDomain[i].Tag == "" {
log.Println("域名分流规则中中Tag为空,采用:", conf.StreamDomain[i].Interface)
conf.StreamDomain[i].Tag = conf.StreamDomain[i].Interface
}
}
return nil
}