package main import ( "encoding/json" "net/netip" "os" "log" ) var config RuntimeConfig type RuntimeConfig struct { Devices DevicesConfig Web WebConfig } type DevicesConfig struct { Hs100 []Hs100Conf } type WebConfig struct { Listen netip.AddrPort } // parseConfig() parses and validates the runtime configuration file and // returns it as Go datastructure. func parseConfig(path string) { data, err := os.ReadFile(path) if err != nil { log.Fatalf("Could not read '%s'!", path) } if !json.Valid(data) { log.Fatalf("%s contains invalid JSON!", path) } err = json.Unmarshal(data, &config) if err != nil { log.Fatalf("Could not parse configuration file:\n%s\n", err) } }