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
744 B
29 lines
744 B
4 months ago
|
package config
|
||
|
|
||
|
import (
|
||
|
"github.com/spf13/viper"
|
||
|
"product/backend/moo/log"
|
||
|
)
|
||
|
|
||
|
func Init() {
|
||
|
// 默认值
|
||
|
defaultConfig()
|
||
|
|
||
|
// 解析配置文件
|
||
|
viper.AddConfigPath(".") // 查找配置文件所在的路径
|
||
|
viper.SetConfigName("config") // 配置文件名称(无扩展名)
|
||
|
viper.SetConfigType("yaml") // 如果配置文件的名称中没有扩展名,则需要配置此项
|
||
|
|
||
|
// 查找并读取配置文件
|
||
|
if err := viper.ReadInConfig(); err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func defaultConfig() {
|
||
|
viper.SetDefault("app.jpegQuality", 60)
|
||
|
viper.SetDefault("app.main.addr", ":8000")
|
||
|
viper.SetDefault("db.driver", "MySQL")
|
||
|
viper.SetDefault("db.dsn", "root:@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local")
|
||
|
}
|