-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
39 lines (30 loc) · 731 Bytes
/
config.go
File metadata and controls
39 lines (30 loc) · 731 Bytes
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
package main
import (
"io/ioutil"
"log"
"os"
"gopkg.in/yaml.v2"
)
func readConfigFile(path string) Config {
var config Config
yamlText, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("Can't read %s: %v", path, err)
}
err = yaml.Unmarshal(yamlText, &config)
if err != nil {
log.Fatalf("Can't unmarshal YAML from %s: %v", path, err)
}
// overrides from environment
if url, found := os.LookupEnv("SLACK_WEB_HOOK"); found {
config.SlackWebHook = url
}
if license, found := os.LookupEnv("NR_LICENSE"); found {
config.NrLicense = license
}
if passwd, found := os.LookupEnv("TUNNELBROKER_PASSWORD"); found {
config.TunnelBroker.Password = passwd
}
// TODO: param validation
return config
}