package global import ( "eta_gn/eta_obs/config" "eta_gn/eta_obs/utils" "fmt" "github.com/fsnotify/fsnotify" "github.com/minio/minio-go/v7" oplogging "github.com/op/go-logging" "github.com/spf13/viper" ) var ( CONFIG config.Config //配置文件 LOG *oplogging.Logger FILE_LOG *oplogging.Logger // 自定义的输出日志 MinioClient *minio.Client ) const ConfigFile = "config/config_debug.yaml" //本地(测试)环境下的配置文件地址 const ProConfigFile = "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 } // handleConfig // @Description: 配置文件处理 // @author: Roc // @datetime 2024-03-13 10:27:40 // @param v *viper.Viper // @param handleType string func handleConfig(v *viper.Viper, handleType string) { if err := v.Unmarshal(&CONFIG); err != nil { fmt.Println(handleType+"赋值失败,Err:", err) } //if CONFIG.Mysql.Binlog.LogSaveDay == 0 { // CONFIG.Mysql.Binlog.LogSaveDay = 31 //} //fmt.Println(CONFIG) //fmt.Println(CONFIG.Mysql.UpdateLogSaveDay) }