-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
71 lines (54 loc) · 1.24 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
package common
import (
"os"
"github.com/spf13/viper"
)
type Common struct {
Identifier string
Components []struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
} `json:"components"`
Alarm struct {
Enabled bool
Interval float64
Webhook_urls []string
}
Redmine struct {
Enabled bool
Project_id string
Tracker_id int
Status_id int
Priority_id int
Interval float64
Api_key string
Url string
}
}
func ConfExists(configName string) bool {
yamlFiles := [2]string{configName + ".yaml", configName + ".yml"}
for _, file := range yamlFiles {
// Check if the file exists
if _, err := os.Stat("/etc/mono/" + file); err == nil {
return true
}
}
return false
}
func ConfInit(configName string, config interface{}) interface{} {
viper.SetConfigName(configName)
viper.AddConfigPath("/etc/mono")
viper.SetConfigType("yaml")
viper.SetDefault("alarm.interval", 3)
err := viper.ReadInConfig()
if err != nil {
LogError("Fatal error while trying to parse the config file: \n" + err.Error())
panic(err)
}
err = viper.Unmarshal(&config)
if err != nil {
LogError("Fatal error while trying to unmarshal the config file: \n" + err.Error())
panic(err)
}
return config
}