-
Notifications
You must be signed in to change notification settings - Fork 102
/
config.go
55 lines (45 loc) · 1.2 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
package config
import (
"io/ioutil"
"log"
"os"
yaml "gopkg.in/yaml.v2"
)
type Config struct {
Providers []Provider `yaml:"providers"`
EnableMonitorDeletion bool `yaml:"enableMonitorDeletion"`
MonitorNameTemplate string `yaml:"monitorNameTemplate"`
}
type Provider struct {
Name string `yaml:"name"`
ApiKey string `yaml:"apiKey"`
ApiURL string `yaml:"apiURL"`
AlertContacts string `yaml:"alertContacts"`
AlertIntegrations string `yaml:"alertIntegrations"`
Username string `yaml:"username"`
Password string `yaml:"password"`
AccountEmail string `yaml:"accountEmail"`
}
func ReadConfig(filePath string) Config {
var config Config
// Read YML
log.Println("Reading YAML Configuration", filePath)
source, err := ioutil.ReadFile(filePath)
if err != nil {
log.Panic(err)
}
// Unmarshall
err = yaml.Unmarshal(source, &config)
if err != nil {
log.Panic(err)
}
return config
}
func GetControllerConfig() Config {
configFilePath := os.Getenv("CONFIG_FILE_PATH")
if len(configFilePath) == 0 {
configFilePath = "../../configs/testConfigs/test-config.yaml"
}
config := ReadConfig(configFilePath)
return config
}