-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
59 lines (50 loc) · 1.12 KB
/
Copy pathconfig.go
File metadata and controls
59 lines (50 loc) · 1.12 KB
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
58
59
package main
import (
"io/ioutil"
"log"
"github.com/BurntSushi/toml"
)
type Config struct {
OAuth OAuthConfig
HTTP HTTPConfig
PollInterval int `toml:"poll_interval"`
QueryStats []string `toml:"query_stats"`
ConvertToF bool `toml:"convert_to_f"`
OpenTSDB OpenTSDBConfig
Backend string
File FileStateConfig
Redis RedisStateConfig
}
type HTTPConfig struct {
Port int
}
// These are found at https://mytaglist.com/eth/oauth2_apps.html
type OAuthConfig struct {
ID string
Secret string
}
type OpenTSDBConfig struct {
Host string
Port int
MetricsPrefix string `toml:"metrics_prefix"`
}
type FileStateConfig struct {
Filename string
}
type RedisStateConfig struct {
Host string
Port int
Key string
}
func ReadConfigFile(filename string) *Config {
config := new(Config)
tomlData, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatalf("Failed to read config file: %s\n", err.Error())
}
_, err = toml.Decode(string(tomlData), config)
if err != nil {
log.Fatalf("Failed to parse config file: %s\n", err.Error())
}
return config
}