-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
44 lines (34 loc) · 858 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
package main
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)
func initConfig() {
log.New()
logLevel, err := log.ParseLevel(viper.GetString("log.level"))
if err != nil {
fmt.Println("Invalid log level specified:", err)
os.Exit(1)
}
log.SetLevel(logLevel)
// Don't forget to read config either from cfgFile or from home directory!
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
log.Fatalln(err)
}
// Search config in home directory with name ".cobra" (without extension).
viper.AddConfigPath(home)
viper.AddConfigPath("./.config/")
viper.AddConfigPath(".")
viper.SetConfigName(".protomagic")
}
_ = viper.ReadInConfig()
}