gin-vue-admin
gin-vue-admin copied to clipboard
[Bug]: viper在容器中运行,挂载到宿主机的config.yaml修改后viper不能触发watch
gin-vue-admin 版本
最新master分支
Node 版本
v14.16.1
Golang 版本
go 1.17
是否依旧存在
可以
bug描述
我通过指定目录也无法watch gin.SetMode(os.Getenv("GIN_MODE")) switch gin.Mode() { case gin.DebugMode: defaultConfigFile = "config_dev.yaml" case gin.TestMode: defaultConfigFile = "config_test.yaml" case gin.ReleaseMode: defaultConfigFile = "config_prod.yaml" } v := viper.New() v.SetConfigFile("/root/server/"+defaultConfigFile) err := v.ReadInConfig() if err != nil { panic(fmt.Errorf("Fatal error config file: %s \n", err)) } v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("---->dong")
logger.WithContext(context.Background()).Info(fmt.Sprintf("config file changed:%s", e.Name))
if err := v.Unmarshal(&global.CONFIG); err != nil {
fmt.Println(err)
}
})
if err := v.Unmarshal(&global.CONFIG); err != nil {
fmt.Println(err)
}
修改建议
是否是viper的bug?但没搜到解决方案。
https://github.com/spf13/viper/issues/920
目前没有好的解决方案,只能考虑修改配置后重新启动项目生效