-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (44 loc) · 1.35 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
52
package main
import (
"gopkg.in/yaml.v2"
"io/ioutil"
)
type Config struct {
Bluetooth *BluetoothConfig `yaml:"bluetooth,omitempty"`
MQTT MQTTConfig `yaml:"mqtt"`
Devices map[string]DeviceConfig `yaml:"devices"`
}
type TLSConfig struct {
InsecureSkipVerify bool `yaml:"insecure,omitempty"`
}
type DeviceConfig struct {
MountPoint string `yaml:"mountpoint"`
RGBCharacteristic *string `yaml:"rgb_characteristic,omitempty"`
NotifyCharacteristic *string `yaml:"notify_characteristic,omitempty"`
ReadStatusInterval *float64 `yaml:"read_status_interval,omitempty"`
}
type BluetoothConfig struct {
Adapter *string `yaml:"adapter,omitempty"`
ResetProgram *string `yaml:"reset_prog,omitempty"`
}
type MQTTConfig struct {
MountPoint *string `yaml:"mountpoint,omitempty"`
Servers []string `yaml:"servers"`
ClientID *string `yaml:"client_id,omitempty"`
Username *string `yaml:"username,omitempty"`
Password *string `yaml:"password,omitempty"`
TLS *TLSConfig `yaml:"tls,omitempty"`
}
func UnmarshalConfig(yml []byte, config *Config) (err error) {
err = yaml.Unmarshal(yml, config)
return
}
func ReadConfig(path string) (config Config, err error) {
var content []byte
content, err = ioutil.ReadFile(path)
if err != nil {
return
}
err = UnmarshalConfig(content, &config)
return
}