|
|
@ -1,8 +1,11 @@
|
|
|
|
package config
|
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"github.com/fsnotify/fsnotify"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
|
|
|
"luxshare-daily-report/global"
|
|
|
|
|
|
|
|
"luxshare-daily-report/model"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
@ -13,7 +16,7 @@ import (
|
|
|
|
// @Description: 初始化配置文件
|
|
|
|
// @Description: 初始化配置文件
|
|
|
|
// @return Config
|
|
|
|
// @return Config
|
|
|
|
//
|
|
|
|
//
|
|
|
|
func InitialConfig() Config {
|
|
|
|
func InitialConfig() model.Config {
|
|
|
|
workPath, _ := os.Executable()
|
|
|
|
workPath, _ := os.Executable()
|
|
|
|
filePath := path.Dir(workPath)
|
|
|
|
filePath := path.Dir(workPath)
|
|
|
|
filePath = filepath.Join(filePath, "/config/.yml")
|
|
|
|
filePath = filepath.Join(filePath, "/config/.yml")
|
|
|
@ -22,24 +25,22 @@ func InitialConfig() Config {
|
|
|
|
viper.AddConfigPath("./config")
|
|
|
|
viper.AddConfigPath("./config")
|
|
|
|
viper.AddConfigPath("../config")
|
|
|
|
viper.AddConfigPath("../config")
|
|
|
|
viper.AddConfigPath(filePath)
|
|
|
|
viper.AddConfigPath(filePath)
|
|
|
|
|
|
|
|
viper.OnConfigChange(func(e fsnotify.Event) {
|
|
|
|
|
|
|
|
log.Printf("[INFO] 配置文件更新: %v", e.Name)
|
|
|
|
|
|
|
|
global.GLO_CONFIG_CHAN <- getConfig()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
viper.WatchConfig()
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Println("未找到配置,请先添加配置!!!")
|
|
|
|
log.Println("[ERROR] 未找到配置,请先添加配置")
|
|
|
|
os.Exit(1)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Printf("[INFO] Loaded Config Success...")
|
|
|
|
log.Printf("[INFO] Loaded Config Success...")
|
|
|
|
return getConfig()
|
|
|
|
return getConfig()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
func getConfig() model.Config {
|
|
|
|
Quality string
|
|
|
|
var config model.Config
|
|
|
|
UserName string
|
|
|
|
|
|
|
|
PassWord string
|
|
|
|
|
|
|
|
BarkUrl string
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getConfig() Config {
|
|
|
|
|
|
|
|
var config Config
|
|
|
|
|
|
|
|
config.Quality = viper.GetString("img.quality")
|
|
|
|
config.Quality = viper.GetString("img.quality")
|
|
|
|
config.UserName = viper.GetString("info.username")
|
|
|
|
config.UserName = viper.GetString("info.username")
|
|
|
|
config.PassWord = viper.GetString("info.password")
|
|
|
|
config.PassWord = viper.GetString("info.password")
|
|
|
|