Skip to content

Commit 69d5568

Browse files
committed
修复配置文件修改后自动监控发生的数据竞争问题,
1 parent 4dd5c23 commit 69d5568

File tree

12 files changed

+117
-336
lines changed

12 files changed

+117
-336
lines changed

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ func getViperConfig() viper_server.ViperConfig {
8484
}
8585
// 监控配置文件变化
8686
vi.SetConfigName(configName)
87-
vi.WatchConfig()
88-
vi.OnConfigChange(func(e fsnotify.Event) {
89-
fmt.Println("配置发生变化:", e.Name)
90-
if err := vi.Unmarshal(&CONFIG); err != nil {
91-
fmt.Printf("反序列化错误: %v \n", err)
92-
}
93-
})
9487
return nil
9588
},
9689
// 注意:设置默认配置值的时候,前面不能有空格等其他符号.必须紧贴左侧.

README_EN.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ func getViperConfig() viper_server.ViperConfig {
8282
}
8383
// config file change
8484
vi.SetConfigName(configName)
85-
vi.WatchConfig()
86-
vi.OnConfigChange(func(e fsnotify.Event) {
87-
fmt.Println("config file change:", e.Name)
88-
if err := vi.Unmarshal(&CONFIG); err != nil {
89-
fmt.Printf("deserialization data error: %v \n", err)
90-
}
91-
})
9285
return nil
9386
},
9487
// Note: When setting the default configuration value, there can be no other symbols such as spaces in front. It must be close to the left

doc.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ func getViperConfig() viper_server.ViperConfig {
7777
}
7878
// config file change
7979
vi.SetConfigName(configName)
80-
vi.WatchConfig()
81-
vi.OnConfigChange(func(e fsnotify.Event) {
82-
fmt.Println("config file change:", e.Name)
83-
if err := vi.Unmarshal(&CONFIG); err != nil {
84-
fmt.Printf("deserialization data error: %v \n", err)
85-
}
86-
})
8780
return nil
8881
},
8982
// Note: When setting the default configuration value, there can be no other symbols such as spaces in front. It must be close to the left

go.mod

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/mattn/go-colorable v0.1.12
2222
github.com/robfig/cron/v3 v3.0.1
2323
github.com/snowlyg/helper v0.0.7
24-
github.com/spf13/viper v1.8.1
24+
github.com/spf13/viper v1.12.0
2525
github.com/unrolled/secure v1.0.9
2626
go.uber.org/zap v1.19.1
2727
gorm.io/driver/mysql v1.1.2
@@ -36,7 +36,6 @@ require (
3636
github.com/Shopify/goreferrer v0.0.0-20210630161223-536fa16abd6f // indirect
3737
github.com/andybalholm/brotli v1.0.4 // indirect
3838
github.com/aymerick/douceur v0.2.0 // indirect
39-
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible // indirect
4039
github.com/cespare/xxhash/v2 v2.1.2 // indirect
4140
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc // indirect
4241
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
@@ -49,7 +48,6 @@ require (
4948
github.com/go-sql-driver/mysql v1.6.0 // indirect
5049
github.com/goccy/go-json v0.9.8-0.20220506185958-23bd66f4c0d5 // indirect
5150
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
52-
github.com/golang/protobuf v1.5.2 // indirect
5351
github.com/golang/snappy v0.0.4 // indirect
5452
github.com/google/uuid v1.3.0 // indirect
5553
github.com/gorilla/css v1.0.0 // indirect
@@ -64,6 +62,7 @@ require (
6462
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
6563
github.com/jackc/pgtype v1.6.2 // indirect
6664
github.com/jackc/pgx/v4 v4.10.1 // indirect
65+
github.com/jinzhu/copier v0.3.5 // indirect
6766
github.com/jinzhu/inflection v1.0.0 // indirect
6867
github.com/jinzhu/now v1.1.2 // indirect
6968
github.com/jonboulle/clockwork v0.2.2 // indirect
@@ -77,26 +76,25 @@ require (
7776
github.com/klauspost/compress v1.15.6 // indirect
7877
github.com/leodido/go-urn v1.2.1 // indirect
7978
github.com/lestrrat-go/strftime v1.0.5 // indirect
80-
github.com/magiconair/properties v1.8.5 // indirect
79+
github.com/magiconair/properties v1.8.6 // indirect
8180
github.com/mailgun/raymond/v2 v2.0.46 // indirect
8281
github.com/mailru/easyjson v0.7.7 // indirect
8382
github.com/mattn/go-isatty v0.0.14 // indirect
8483
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
85-
github.com/mitchellh/mapstructure v1.4.1 // indirect
84+
github.com/mitchellh/mapstructure v1.5.0 // indirect
8685
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
8786
github.com/modern-go/reflect2 v1.0.2 // indirect
88-
github.com/pelletier/go-toml v1.9.3 // indirect
87+
github.com/pelletier/go-toml v1.9.5 // indirect
8988
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
9089
github.com/pkg/errors v0.9.1 // indirect
9190
github.com/russross/blackfriday/v2 v2.1.0 // indirect
9291
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
9392
github.com/sirupsen/logrus v1.8.1 // indirect
94-
github.com/spf13/afero v1.6.0 // indirect
95-
github.com/spf13/cast v1.3.1 // indirect
93+
github.com/spf13/afero v1.8.2 // indirect
94+
github.com/spf13/cast v1.5.0 // indirect
9695
github.com/spf13/jwalterweatherman v1.1.0 // indirect
9796
github.com/spf13/pflag v1.0.5 // indirect
98-
github.com/stretchr/testify v1.7.2 // indirect
99-
github.com/subosito/gotenv v1.2.0 // indirect
97+
github.com/subosito/gotenv v1.3.0 // indirect
10098
github.com/tdewolff/minify/v2 v2.11.9 // indirect
10199
github.com/tdewolff/parse/v2 v2.5.33 // indirect
102100
github.com/ugorji/go/codec v1.2.7 // indirect
@@ -111,7 +109,7 @@ require (
111109
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68 // indirect
112110
golang.org/x/text v0.3.7 // indirect
113111
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
114-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
112+
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
115113
google.golang.org/protobuf v1.28.0 // indirect
116114
gopkg.in/ini.v1 v1.66.6 // indirect
117115
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)