-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
51 lines (42 loc) · 920 Bytes
/
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
package config
import (
log "github.com/Sirupsen/logrus"
"github.com/spf13/viper"
)
// Config representation
type Config struct {
LogLevel string
Slack struct {
Token string
Channel string
IconEmoji string
}
Gitlab struct {
WebhookSecret string
APIToken string
BaseURL string
SkipSSLVerify bool
}
Server struct {
Port int
}
}
// LoadConfig is used to create an Config struct
func LoadConfig(cfgFile string) *Config {
var conf Config
viper.SetConfigFile(cfgFile)
viper.SetDefault("Gitlab.SkipSSLVerify", false)
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("Error reading config file, %s", err)
}
err := viper.Unmarshal(&conf)
if err != nil {
log.Fatalf("unable to decode into struct, %v", err)
}
lvl, err := log.ParseLevel(conf.LogLevel)
if err != nil {
log.Error("Invalid log level:" + conf.LogLevel)
}
log.SetLevel(lvl)
return &conf
}