feat: omc原始代码
This commit is contained in:
36
lib/core/conf/conf.go
Normal file
36
lib/core/conf/conf.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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("读取配置文件失败: %v \n", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Get 获取配置信息
|
||||
//
|
||||
// Get("framework.name")
|
||||
func Get(key string) any {
|
||||
return v.Get(key)
|
||||
}
|
||||
|
||||
// AllSettings 全部配置信息
|
||||
func AllSettings() map[string]interface{} {
|
||||
return v.AllSettings()
|
||||
}
|
||||
Reference in New Issue
Block a user