package main import ( "encoding/json" "fmt" "os" "git.rnrd.eu/ddnnss/provider" "git.rnrd.eu/ddnnss/source" ) // a record target which we will try to update // via the provider! type Record struct { Zone string `json:"zone"` Name string `json:"name"` Type provider.RecordType `json:"type"` Provider string `json:"provider"` Source string `json:"source"` } type Config struct { Records []Record `json:"records"` Providers map[string]provider.Config `json:"providers"` Sources map[string]source.Config `json:"sources"` } func LoadConfig(path string) (*Config, error) { raw, err := os.ReadFile(path) if err != nil { return nil, err } var cfg Config if err := json.Unmarshal(raw, &cfg); err != nil { return nil, fmt.Errorf("%s: %w", path, err) } for i, r := range cfg.Records { switch r.Type { case provider.TypeA, provider.TypeAAAA: default: return nil, fmt.Errorf("record %d: type must be A or AAAA", i) } if _, ok := cfg.Providers[r.Provider]; !ok { return nil, fmt.Errorf("record %d: unknown provider %q", i, r.Provider) } if _, ok := cfg.Sources[r.Source]; !ok { return nil, fmt.Errorf("record %d: unknown source %q", i, r.Source) } } return &cfg, nil }