/
config.go
55 lines (42 loc) · 824 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
package main
import (
"github.com/martin2250/minitsdb/pkg/apiclient"
"gopkg.in/yaml.v3"
"log"
"os"
"time"
)
type WatchConfig struct {
Series map[string]string
Column apiclient.Column
TimeRange time.Duration
TimeStep time.Duration
Range *struct {
Min float64
Max float64
}
MinPoints *int
Interval time.Duration
}
type Configuration struct {
Address string
Watches []WatchConfig
Telegram struct {
ApiToken string
ChatID int64
}
}
func readConfigurationFile(confpath string) Configuration {
conf := Configuration{}
f, err := os.Open(confpath)
if err != nil {
log.Fatalf("could not open configuration file %v", err)
}
defer f.Close()
dec := yaml.NewDecoder(f)
err = dec.Decode(&conf)
if err != nil {
log.Fatalf("could not parse configuration file %v", err)
}
return conf
}