blob: 3bb153bc9dc4c5794915f6cc175be756a82813ac (
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
39
40
41
42
|
package main
import (
"encoding/json"
"net/netip"
"os"
"log"
)
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) RuntimeConfig {
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)
}
config := RuntimeConfig{}
err = json.Unmarshal(data, &config)
if err != nil {
log.Fatalf("Could not parse configuration file:\n%s\n", err)
}
return config
}
|