forked from newrelic/sidecar
/
config.go
86 lines (70 loc) · 2.18 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"time"
"github.com/BurntSushi/toml"
)
type ListenerUrlsConfig struct {
Urls []string `toml:"urls"`
}
type HAproxyConfig struct {
ReloadCmd string `toml:"reload_command"`
VerifyCmd string `toml:"verify_command"`
BindIP string `toml:"bind_ip"`
TemplateFile string `toml:"template_file"`
ConfigFile string `toml:"config_file"`
PidFile string `toml:"pid_file"`
Disable bool `toml:"disable"`
User string `toml:"user"`
Group string `toml:"group"`
UseHostnames bool `toml:"use_hostnames"`
}
type ServicesConfig struct {
NameMatch string `toml:"name_match"`
ServiceNamer string `toml:"namer"`
NameLabel string `toml:"name_label"`
}
type SidecarConfig struct {
ExcludeIPs []string `toml:"exclude_ips"`
Discovery []string `toml:"discovery"`
StatsAddr string `toml:"stats_addr"`
PushPullInterval duration `toml:"push_pull_interval"`
GossipMessages int `toml:"gossip_messages"`
LoggingFormat string `toml:"logging_format"`
LoggingLevel string `toml:"logging_level"`
DefaultCheckEndpoint string `toml:"default_check_endpoint"`
}
type DockerConfig struct {
DockerURL string `toml:"docker_url"`
}
type StaticConfig struct {
ConfigFile string `toml:"config_file"`
}
type Config struct {
Sidecar SidecarConfig `toml:"sidecar"`
DockerDiscovery DockerConfig `toml:"docker_discovery"`
StaticDiscovery StaticConfig `toml:"static_discovery"`
Services ServicesConfig `toml:"services"`
HAproxy HAproxyConfig `toml:"haproxy"`
Listeners ListenerUrlsConfig `toml:"listeners"`
}
func setDefaults(config *Config) {
config.DockerDiscovery.DockerURL = "tcp://localhost:2375"
config.StaticDiscovery.ConfigFile = "static.json"
}
type duration struct {
time.Duration
}
func (d *duration) UnmarshalText(text []byte) error {
var err error
d.Duration, err = time.ParseDuration(string(text))
return err
}
func parseConfig(path string) Config {
var config Config
setDefaults(&config)
_, err := toml.DecodeFile(path, &config)
if err != nil {
exitWithError(err, "Failed to parse config file")
}
return config
}