ADd consul support , multiple monitors, config file
This commit is contained in:
39
config/config.go
Normal file
39
config/config.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Agent struct {
|
||||
ListenAddr string `yaml:"listen_addr"`
|
||||
MonitorInterval time.Duration `yaml:"monitor_interval"`
|
||||
CleanupTimer time.Duration `yaml:"cleanup_timer"`
|
||||
ConsulAddr string `yaml:"consul_addr"`
|
||||
ConsulQueryInterval time.Duration `yaml:"consul_query_interval"`
|
||||
}
|
||||
Bgp struct {
|
||||
LocalAS int `yaml:"local_as"`
|
||||
PeerAS int `yaml:"peer_as"`
|
||||
PeerIP string `yaml:"peer_ip"`
|
||||
Communities []string
|
||||
Origin string
|
||||
}
|
||||
}
|
||||
|
||||
func GetConfig(file string) *Config {
|
||||
absPath, _ := filepath.Abs(file)
|
||||
data, err := ioutil.ReadFile(absPath)
|
||||
if err != nil {
|
||||
glog.Exitf("FATAL: Unable to read config file: %v", err)
|
||||
}
|
||||
config := &Config{}
|
||||
if err := yaml.Unmarshal(data, config); err != nil {
|
||||
glog.Exitf("FATAL: Unable to decode yaml: %v", err)
|
||||
}
|
||||
return config
|
||||
}
|
||||
Reference in New Issue
Block a user