-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
39 lines (33 loc) · 832 Bytes
/
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
package main
import (
"gopkg.in/yaml.v2"
"io/ioutil"
)
type sensor struct {
Name string `yaml:"name"`
Unit string `yaml:"unit"`
Icon string `yaml:"icon"`
StateTopic string `yaml:"state_topic"`
ValueTemplate string `yaml:"value_template"`
}
type config struct {
Name string `yaml:"name"`
Manufacturer string `yaml:"manufacturer"`
Model string `yaml:"model"`
MqttServer string `yaml:"mqtt_server"`
SerialPort string `yaml:"serial_port"`
Topic string `yaml:"topic"`
HaRegister bool `yaml:"ha_register"`
Sensors []sensor `yaml:"sensors"`
}
func parseYaml(path string, c interface{}) error {
cfg, err := ioutil.ReadFile(path)
if err != nil {
return err
}
err = yaml.Unmarshal(cfg, c)
if err != nil {
return err
}
return nil
}