From 1ca4879df9cc3c22181b2a200aa4b793116d3d35 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期六, 19 十月 2024 16:23:55 +0800
Subject: [PATCH] fix id
---
config/config.go | 35 ++++++++++++++++++++++++++++-------
1 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/config/config.go b/config/config.go
index 1fc82e0..48f1697 100644
--- a/config/config.go
+++ b/config/config.go
@@ -1,25 +1,46 @@
package config
import (
+ "github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"log"
)
-type servUrls struct {
- EsUrl string `mapstructure: "esUrl"`
- ServerUrl string `mapstructure: "serverUrl"`
+type common struct {
+ EsUrl string `mapstructure:"esUrl"`
+ ServerUrl string `mapstructure:"serverUrl"`
+ OrgName string `mapstructure:"orgName"`
+ Interval int `mapstructure:"pushInterval"`
}
-var ServUrls = &servUrls{}
+type logConfig struct {
+ Path string `mapstructure:"path"` //鏃ュ織瀛樺偍璺緞
+ Level int `mapstructure:"level"` //鏃ュ織绛夌骇
+ MaxSize int `mapstructure:"maxSize"` //鏃ュ織鏂囦欢澶у皬涓婇檺
+ MaxBackups int `mapstructure:"maxBackups"` //鏃ュ織鍘嬬缉鍖呬釜鏁�
+ MaxAge int `mapstructure:"maxAge"` //淇濈暀鍘嬬缉鍖呭ぉ鏁�
+}
-func Init(env string) {
+var Options = &common{}
+var LogConf = &logConfig{}
+
+func Init() {
var err error
viper.SetConfigType("yaml")
- viper.SetConfigName(env)
+ viper.SetConfigName("esSyncClient")
viper.AddConfigPath("config")
+ viper.AddConfigPath("../config")
+ viper.AddConfigPath("")
err = viper.ReadInConfig()
if err != nil {
log.Fatal("error on parsing configuration file", err)
}
- viper.UnmarshalKey("servUrls", ServUrls)
+
+ viper.UnmarshalKey("common", Options)
+ viper.UnmarshalKey("log", LogConf)
+
+ viper.WatchConfig()
+ viper.OnConfigChange(func(in fsnotify.Event) {
+ viper.UnmarshalKey("common", Options)
+ })
}
--
Gitblit v1.8.0