blob: 38f0af9301f26c10c59f0ea5404a9edd89efd1f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}
|