-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
48 lines (38 loc) · 995 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
package main
import (
"gopkg.in/yaml.v3"
"io"
)
type DNSConfig struct {
Listen string `yaml:"listen"`
Network string `yaml:"network"`
AuthoritativeDNS string `yaml:"authoritative_dns"`
}
type BGPNeighborsConfig struct {
ASN uint32 `yaml:"asn"`
Prefix string `yaml:"prefix"`
}
type BGPConfig struct {
ListenPort uint16 `yaml:"listen"`
RouterID string `yaml:"router_id"`
ASN uint32 `yaml:"asn"`
Neighbors BGPNeighborsConfig `yaml:"neighbors"`
}
type RulesConfig struct {
NextHop string `yaml:"next_hop"`
Zones Zones `yaml:"zones"`
Networks []string `yaml:"networks"`
}
type Config struct {
DNS DNSConfig `yaml:"dns"`
BGP BGPConfig `yaml:"bgp"`
Rules RulesConfig `yaml:"rules"`
}
func ReadConfig(r io.Reader) (Config, error) {
var config Config
if err := yaml.NewDecoder(r).Decode(&config); err != nil {
return Config{}, err
}
config.Rules.Zones.Normalize()
return config, nil
}