package config import ( yaml "gopkg.in/yaml.v2" "io" "os" "time" ) type Config struct { Interval time.Duration `yaml:"interval"` Listen string `yaml:"listen"` DebugLevel int `yaml:"debug_level"` APIKey string `yaml:"api_key"` APIKeyFile string `yaml:"api_key_file"` WebRoot string `yaml:"web_root"` Hosts []Host `yaml:"hosts"` Alarms []Alarm `yaml:"alarms"` Groups map[string][]Host `yaml:"groups"` } func New() *Config { return &Config{ Interval: 30 * time.Second, Listen: "127.0.0.1:8282", DebugLevel: 0, WebRoot: "/", } } func ReadConfig(fn string, debuglvl int) (*Config, error) { f, err := os.Open(fn) if err != nil { return nil, err } h, err := io.ReadAll(f) if err != nil { return nil, err } cfg := New() err = yaml.UnmarshalStrict(h, &cfg) if err != nil { return nil, err } err = cfg.Validate() if err != nil { return nil, err } return cfg, nil }