12345678910111213141516171819202122232425 |
- package config
- import (
- "github.com/spf13/viper"
- "os"
- )
- var Config *viper.Viper
- func init() {
- Config = viper.New()
- dir, _ := os.Getwd()
- _, err := os.Stat(dir + "/config.yaml")
- if err != nil {
- panic(any("配置文件不存在,请检查配置文件!"))
- }
- Config.SetConfigName("config")
- Config.SetConfigType("yaml")
- Config.AddConfigPath(dir)
- if err := Config.ReadInConfig(); err != nil {
- panic(any(err.Error()))
- }
- }
|