forked from rancher/host-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
58 lines (47 loc) · 1.33 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
package config
import (
"flag"
"github.com/rakyll/globalconf"
"os"
)
type config struct {
CAdvisorUrl string
DockerUrl string
Systemd bool
NumStats int
Auth bool
Key string
HostUuid string
Port int
Ip string
}
var Config config
func Parse() error {
flag.IntVar(&Config.Port, "port", 8080, "Listen port")
flag.StringVar(&Config.Ip, "ip", "", "Listen IP, defaults to all IPs")
flag.StringVar(&Config.CAdvisorUrl, "cadvisor-url", "http://localhost:8081", "cAdvisor URL")
flag.StringVar(&Config.DockerUrl, "docker-host", "unix:///var/run/docker.sock", "Docker host URL")
flag.IntVar(&Config.NumStats, "num-stats", 600, "Number of stats to show by default")
flag.BoolVar(&Config.Auth, "auth", false, "Authenticate requests")
flag.StringVar(&Config.HostUuid, "host-uuid", "", "Host UUID")
flag.StringVar(&Config.Key, "public-key", "", "Public Key for Authentication")
confOptions := &globalconf.Options{
EnvPrefix: "HOST_API_",
}
filename := os.Getenv("HOST_API_CONFIG_FILE")
if len(filename) > 0 {
confOptions.Filename = filename
}
conf, err := globalconf.NewWithOptions(confOptions)
if err != nil {
return err
}
conf.ParseAll()
s, err := os.Stat("/run/systemd/system")
if err != nil || !s.IsDir() {
Config.Systemd = false
} else {
Config.Systemd = true
}
return nil
}