Files
gocast/config/config.go
Mayuresh Gaitonde 6be4d69d02 Add unit tests
2020-12-17 17:25:53 -08:00

54 lines
1.1 KiB
Go

package config
import (
"io/ioutil"
"path/filepath"
"time"
"github.com/golang/glog"
"gopkg.in/yaml.v2"
)
type AgentConfig 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"`
}
type BgpConfig struct {
LocalAS int `yaml:"local_as"`
PeerAS int `yaml:"peer_as"`
LocalIP string `yaml:"local_ip"`
PeerIP string `yaml:"peer_ip"`
Communities []string
Origin string
}
type AppConfig struct {
Name string
Vip string
Monitors []string
Nats []string
}
type Config struct {
Agent AgentConfig
Bgp BgpConfig
Apps []AppConfig
}
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
}