1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package global
- import (
- "eta/eta_email_analysis/config"
- "eta/eta_email_analysis/utils"
- "fmt"
- "github.com/fsnotify/fsnotify"
- oplogging "github.com/op/go-logging"
- "github.com/spf13/viper"
- "gorm.io/gorm"
- "io"
- )
- var (
- CONFIG config.Config
- LOG *oplogging.Logger
- FILE_LOG *oplogging.Logger
- MYSQL map[string]*gorm.DB
- MYSQL_LOG io.Writer
- DEFAULT_MYSQL *gorm.DB
-
-
- Rc utils.RedisClient
- Re error
- )
- const ConfigFile = "config/config_debug.yaml"
- const ProConfigFile = "/home/code/config/eta_email_analysis/config/config.yaml"
- func init() {
- v := viper.New()
- configFilePath := ConfigFile
-
- if !utils.FileIsExist(configFilePath) {
- configFilePath = ProConfigFile
- }
- fmt.Println("configFilePath->", configFilePath)
-
- v.SetConfigFile(configFilePath)
- err := v.ReadInConfig()
- if err != nil {
- panic(fmt.Errorf("读取配置失败,Err: %s \n", err))
- }
-
- v.WatchConfig()
- v.OnConfigChange(func(e fsnotify.Event) {
- fmt.Println("配置文件变更:", e.Name)
- handleConfig(v, "配置重赋值")
- })
- handleConfig(v, "配置初始化")
- return
- }
- func handleConfig(v *viper.Viper, handleType string) {
- if err := v.Unmarshal(&CONFIG); err != nil {
- fmt.Println(handleType+"赋值失败,Err:", err)
- }
-
-
-
-
-
- }
|