-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
42 lines (35 loc) · 865 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
package main
import (
"fmt"
"io/ioutil"
"time"
yaml "gopkg.in/yaml.v2"
)
type config struct {
Pinba struct {
Addr string `yaml:"host"`
ConnectTimeout time.Duration `yaml:"connect_timeout"`
ReadTimeout time.Duration `yaml:"read_timeout"`
} `yaml:"pinba"`
Influxdb struct {
Addr string `yaml:"addr"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
} `yaml:"influxdb"`
Whitelist struct {
ServerNames []string `yaml:"servers"`
Tags []string `yaml:"tags"`
} `yaml:"whitelist"`
}
func getConfig(filename string) (*config, error) {
file, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
cfg := config{}
if err := yaml.Unmarshal(file, &cfg); err != nil {
return nil, fmt.Errorf("unmarshal failed: %v", err)
}
return &cfg, nil
}