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.

53 lines
1.2 KiB

package config
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"os"
"path"
"path/filepath"
)
//
// InitialConfig
// @Description: 初始化配置文件
// @return Config
//
func InitialConfig() Config {
workPath, _ := os.Executable()
filePath := path.Dir(workPath)
filePath = filepath.Join(filePath, "/config/.yml")
viper.SetConfigName("config")
viper.SetConfigType("yml")
viper.AddConfigPath("./config")
viper.AddConfigPath("../config")
viper.AddConfigPath(filePath)
err := viper.ReadInConfig()
if err != nil {
log.Println("未找到配置,请先添加配置!!!")
os.Exit(1)
}
log.Printf("[INFO] Loaded Config Success...")
return getConfig()
}
type Config struct {
Port string
Quality string
UserName string
PassWord string
UserInfo string
BarkUrl string
}
func getConfig() Config {
var config Config
config.Port = viper.GetString("server.port")
config.Quality = viper.GetString("img.quality")
config.UserName = viper.GetString("info.username")
config.PassWord = viper.GetString("info.password")
config.UserInfo = viper.GetString("info.userinfo")
config.BarkUrl = viper.GetString("message.bark.url")
return config
}