Files
be.ems/lib/core/conf/conf.go

37 lines
563 B
Go

package conf
import (
"fmt"
"github.com/spf13/viper"
)
var v *viper.Viper
// 配置文件读取
func InitConfig(configFile string) {
v = viper.New()
// 设置配置文件路径
v.SetConfigFile(configFile)
// 读取配置文件
err := v.ReadInConfig()
if err != nil {
fmt.Printf("failure to read configuration file: %v \n", err)
return
}
}
// Get 获取配置信息
//
// Get("server.port")
func Get(key string) any {
return v.Get(key)
}
// AllSettings 全部配置信息
func AllSettings() map[string]interface{} {
return v.AllSettings()
}