/
config.go
57 lines (53 loc) · 972 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
type typeConfig struct {
MQTT struct {
Server string
Port int
}
Influx struct {
Addr string
User string
Pass string
Database string
}
Postgres struct {
Connect string
Schema string
}
Logs struct {
Filename string
Prefix string
}
Debug struct {
Filename string
Prefix string
}
Topics map[string]map[string]struct {
Log string
Debug string
Influx string
Postgres string
Exec string
}
}
func (s *server) readConfig() error {
configFileName := "config.yaml"
if s.verbose {
log.Printf("Reading config file %s", configFileName)
}
s.config = typeConfig{}
data, err := ioutil.ReadFile(configFileName)
if err != nil {
return fmt.Errorf("reading %s: %w", configFileName, err)
}
if err := yaml.UnmarshalStrict(data, &s.config); err != nil {
return fmt.Errorf("parsing %s: %w", configFileName, err)
}
return nil
}