Files
webp/models/config.go
2023-11-30 04:03:19 +08:00

44 lines
921 B
Go

package models
import (
"log"
"path/filepath"
"runtime"
"github.com/spf13/viper"
)
var (
_, b, _, _ = runtime.Caller(0)
Root = filepath.Join(filepath.Dir(b), "..")
Viper *viper.Viper
)
func init() {
config_file := filepath.Join(Root, "data", "config.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", "")
viper.Set("video.endpoint", "")
viper.Set("video.accessKeyID", "")
viper.Set("video.accessKey", "")
}