This commit is contained in:
Tony Zou
2019-10-03 13:06:12 +08:00
parent 9e28900872
commit 7c330e2fe8
4 changed files with 256 additions and 0 deletions

38
utils/config.go Normal file
View File

@@ -0,0 +1,38 @@
package utils
import (
"log"
"strings"
"github.com/spf13/viper"
)
// GetConfig returns the global config
func GetConfig() *viper.Viper {
c := viper.New()
c.SetConfigType("yaml")
c.SetConfigName("config")
c.AddConfigPath(".")
c.AutomaticEnv()
c.SetDefault("debug", true)
c.SetDefault("admins", []interface{}{})
c.SetDefault("redis.host", "localhost:6379")
c.SetDefault("redis.db", 0)
c.SetDefault("redis.password", "")
c.SetDefault("crisp.identifier", "")
c.SetDefault("crisp.key", "")
c.SetDefault("telegram.key", "")
replacer := strings.NewReplacer(".", "_")
c.SetEnvKeyReplacer(replacer)
if err := c.ReadInConfig(); err != nil {
log.Fatal(err.Error())
}
return c
}