Crisp_Telegram_bot/utils/config.go

35 lines
588 B
Go
Raw Permalink Normal View History

2019-10-03 08:06:12 +03:00
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("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
}