package main import ( "encoding/json" "os" ) type Config struct { NodeID []byte `json:"nodeID"` Name string `json:"name"` ShortName string `json:"shortName"` DefaultHops uint32 `json:"defaultHops"` MaxHops uint32 `json:"maxHops"` NodeBroadcastInterval float64 `json:"nodeBroadcastInterval"` X25519Key []byte `json:"x25519Key"` Channels []struct { Name string `json:"name"` PSK []byte `json:"psk"` } `json:"channels"` Position struct { BroadcastInterval float64 `json:"broadcastInterval"` Latitude float64 `json:"latitude"` Longitude float64 `json:"longitude"` Altitude float64 `json:"altitude"` } `json:"position"` DeviceMetrics struct { BroadcastInterval float64 `json:"broadcastInterval"` UPSAddress string `json:"upsAddress"` } `json:"deviceMetrics"` KavaModem struct { Address string `json:"address"` } `json:"kavaModem"` MqttIf struct { Address string `json:"address"` Username string `json:"username"` Password string `json:"password"` ClientID string `json:"clientId"` Root string `json:"root"` } `json:"mqttIf"` } func ReadConfig(filename string) (*Config, error) { cfg := Config{} f, err := os.Open(filename) if err != nil { return nil, err } dec := json.NewDecoder(f) if err := dec.Decode(&cfg); err != nil { return nil, err } return &cfg, nil }