Files
webp/models/config.go
2023-04-12 15:35:33 +08:00

40 lines
892 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"log"
"os"
"github.com/spf13/viper"
)
var Viper *viper.Viper
func init() {
//如果命令行参数中有test则使用测试环境的配置
var config_file string = "./data/config.yaml"
if len(os.Args) > 1 && os.Args[1] == "test" {
log.Println("使用测试环境配置")
config_file = "./data/config_test.yaml"
}
viper.SetConfigFile(config_file)
if err := viper.ReadInConfig(); err != nil {
log.Println("读取配置文件失败", err)
生成配置文件()
}
Viper = viper.GetViper()
}
func 生成配置文件() {
viper.Set("mysql.host", "")
viper.Set("mysql.port", 3306)
viper.Set("mysql.user", "")
viper.Set("mysql.password", "")
viper.Set("mysql.dbname", "")
viper.Set("mysql.charset", "utf8mb4")
viper.Set("mysql.maxOpenConns", 100)
viper.Set("oss.endpoint", "")
viper.Set("oss.accessID", "")
viper.Set("oss.accessKey", "")
}