-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (41 loc) · 1005 Bytes
/
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
package main
import (
"os"
"gopkg.in/yaml.v3"
)
type ConfMap struct {
Dns DNSConfMap `yaml:"dns"`
RouterOS RouterOSConf `yaml:"routeros"`
}
type DNSConfMap struct {
Resolvers []string `yaml:"resolvers"`
Names []DNSRecord `yaml:"names"`
}
type DNSRecord struct {
Name string `yaml:"name"`
Target string `yaml:"target"`
}
type RouterOSConf struct {
Address string `yaml:"address"`
UseTLS bool `yaml:"usetls"`
Port int32 `yaml:"port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
VPN VPNConf `yaml:"vpn"`
}
type VPNConf struct {
Interface string `yaml:"interface"`
Dns []string `yaml:"dns"`
WhitelistedDomains []string `yaml:"whitelisted_domains"`
}
func Load(filename string) (*ConfMap, error) {
cf, err := os.Open(filename)
if err != nil {
return nil, err
}
confMap := new(ConfMap)
if err := yaml.NewDecoder(cf).Decode(confMap); err != nil {
return nil, err
}
return confMap, nil
}