-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
51 lines (41 loc) · 1.27 KB
/
config.go
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
43
44
45
46
47
48
49
50
51
package main
import (
"encoding/json"
"log"
"os"
)
type config struct {
IPAddress string `json:"ipAddress,omitempty"`
ChannelStrips []channelStripConfig `json:"channelStrips"`
RecallButton recallButtonConfig `json:"recallButton"`
Language string `json:"language,omitEmpty"`
}
type channelStripConfig struct {
OscAddress string `json:"oscAddress"`
}
type recallButtonConfig struct {
Enabled bool `json:"enabled"`
SceneNr byte `json:"sceneNumber"`
Label string `json:"label"`
}
const maxNumChannelStrips = 9
func loadConfig(fileName string) config {
configFile, err := os.Open("./config.json")
if err != nil {
log.Fatal("Unable to load config.json")
}
defer configFile.Close()
var conf config
err = json.NewDecoder(configFile).Decode(&conf)
if err != nil {
log.Fatalf("Unable to read config.json: %v", err.Error())
}
if len(conf.ChannelStrips) == 0 {
log.Fatalf("No channelStrips configured in config.json.")
}
if len(conf.ChannelStrips) > int(maxNumChannelStrips) {
log.Printf("channelStrips array in config.json contains too many elements. Ony %v channel strips supported. Remaining strips will be ignored.\n", maxNumChannelStrips)
conf.ChannelStrips = conf.ChannelStrips[:maxNumChannelStrips]
}
return conf
}