-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (39 loc) · 1000 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
package main
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Bfd ServerConfig `yaml:"bfd"`
Gobgp ServerConfig `yaml:"gobgp"`
Peers map[string]string `yaml:"peers"`
Logging LoggingConfig `yaml:"logging"`
}
type ServerConfig struct {
Host string `yaml:"host"`
Tls TlsConfig `yaml:"tls,omitempty"`
}
type TlsConfig struct {
Enable bool `yaml:"enable"`
CertFile string `yaml:"cert"`
}
type LoggingConfig struct {
Logfile string `yaml:"logfile"`
LogToStdout bool `yaml:"log-also-to-stdout"`
}
func LoadConfig(path string) (*Config, error) {
// Default config file path to $CWD/config.yml
if len(path) == 0 {
path = "config.yml"
}
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("Error reading config file: %v", err)
}
config := &Config{}
if err := yaml.Unmarshal([]byte(data), config); err != nil {
return nil, fmt.Errorf("Error parsing config file: %v", err)
}
return config, nil
}