You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
770 B
Go

package initialize
import (
"fmt"
"git.echol.cn/loser/logger/log"
"online_code/config"
"github.com/spf13/viper"
)
var localVp *viper.Viper
func initLocaConfig() {
localVp = viper.New()
localVp.SetConfigName("config") // 文件名-无需文件后缀
localVp.SetConfigType("yaml") // 文件扩展名
localVp.AddConfigPath(".")
// 处理读取配置文件的错误
if err := localVp.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
panic(fmt.Errorf("未找到配置文件,请检查路径: %s \n", err))
} else {
panic(fmt.Errorf("文件已找到,但读取文件时出错: %s \n", err))
}
}
// 解析配置文件为结构体
if err := localVp.Unmarshal(&config.Scd); err != nil {
log.Panic(err)
}
}