-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
40 lines (33 loc) · 806 Bytes
/
init.go
File metadata and controls
40 lines (33 loc) · 806 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
40
package main
import (
"flag"
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/train-cat/notifier/api"
"github.com/train-cat/notifier/helper"
)
func init() {
initLogging()
initConfig()
helper.InitHelper()
api.Init()
}
func initLogging() {
log.SetFormatter(&log.TextFormatter{})
log.SetOutput(os.Stderr)
log.SetLevel(log.DebugLevel)
}
func initConfig() {
cfgFile := flag.String("config", "config.json", "config file")
flag.Parse()
viper.SetConfigFile(*cfgFile)
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
log.Infof("Using config file: %s", viper.ConfigFileUsed())
} else {
log.Error(err.Error())
os.Exit(helper.ExitCodeErrorInitConfig)
}
}