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.

29 lines
653 B

package utils
import (
"github.com/spf13/viper"
"log"
)
// 用来处理配置的工具文件
func ParseConfig() {
// 配置默认值
defaultConfig()
// 配置解析文件
viper.AddConfigPath(".") // 解析哪些目录下的配置文件
viper.SetConfigName("config") // 配置文件的名字
viper.SetConfigType("yaml") // 配置文件后缀(类型)
// 执行解析
if err := viper.ReadInConfig(); err != nil {
log.Fatal(err)
}
}
// 配置默认值设置
func defaultConfig() {
viper.SetDefault("app.addr", ":8080")
viper.SetDefault("mysql.dsn", "root:@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local")
}