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

33 lines
605 B

4 months ago
package utils
import (
"github.com/spf13/viper"
"log"
)
// 默认配置
func defaultConfig() {
viper.SetDefault("app.mode", "debug")
viper.SetDefault("app.addr", ":8080")
4 months ago
viper.SetDefault("app.log.path", "./logs")
4 months ago
}
// ParseConfig 解析配置
func ParseConfig() {
//1.默认配置
defaultConfig()
//2.配置解析函数
viper.AddConfigPath(".") // 从哪些目录搜索配置文件
viper.SetConfigName("configs") // 配置文件名字
viper.SetConfigType("yaml") // 配置类型(格式)
//3.执行解析
err := viper.ReadInConfig()
if err != nil {
log.Fatal(err)
}
}