diff options
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/config.go b/config.go new file mode 100644 index 0000000..38f0af9 --- /dev/null +++ b/config.go @@ -0,0 +1,38 @@ +package main + +import ( + _ "embed" + "encoding/json" + "log" +) + +//go:embed configs/default.json +var defaultConfig []byte + +type StartupConfig struct { + MQTT struct { + Broker string `json:"broker"` + ClientID string `json:"client-id"` + TopicPrefix string `json:"topic-prefix"` + } `json:"mqtt"` + + Homematic struct { + CCU string `json:"ccu"` + PollingPeriodMilliseconds int `json:"polling-period-milliseconds"` + } `json:"homematic"` +} + +func (sc *StartupConfig) FromJSON(data []byte) error { + return json.Unmarshal(data, sc) +} + +func GetStartupConfig() StartupConfig { + config := StartupConfig{} + + err := config.FromJSON(defaultConfig) + if err != nil { + log.Fatalf("Could not parse default config: %v", err) + } + + return config +} |
