package main import ( "fmt" "github.com/pelletier/go-toml" "os" ) type Config struct { ServerPort uint16 `toml:"port"` RRConfigs []RRConfig `toml:"rrconfig"` rrconfigs map[string]*RRConfig } type RRConfig struct { Username string `toml:"username"` Password string `toml:"password"` Nameserver string `toml:"nameserver"` Zonename string `toml:"zonename"` Hostname string `toml:"hostname"` Tsigkey string `toml:"tsigkey"` Ttl int `toml:"ttl" default:"60"` } func LoadConfig(path string) (*Config, error) { var cfg Config f, err := os.Open(path) if err != nil { return nil, err } decoder := toml.NewDecoder(f).Strict(true) err = decoder.Decode(&cfg) if err != nil { return nil, err } cfg.rrconfigs = map[string]*RRConfig{} for _, entry := range cfg.RRConfigs { if _, ok := cfg.rrconfigs[entry.Username]; ok { return nil, fmt.Errorf("Duplicate username detected") } cfg.rrconfigs[entry.Username] = &entry } return &cfg, nil }