go-config的watch next似乎对文件变化没反应?
sidazhang123 opened this issue · 2 comments
sidazhang123 commented
从官方文档贴了load和watch的代码组成如下最小集(server端),按理解应该是文件变化后watcher.Next()就会返回,但是依然阻塞。目标文件所有字段都尝试过更改,均无法触发。望解答,感谢!
type Host struct {
Address string `json:"address"`
Port int `json:"port"`
}
type Config struct{
Hosts map[string]Host `json:"hosts"`
}
var conf Config
func main(){
config.Load(file.NewSource(
file.WithPath("test.json"),
))
config.Scan(&conf)
fmt.Printf("%+v",conf)
w, _ := config.Watch("hosts", "database")
v, _ := w.Next() //卡在这里
var host Host
v.Scan(&host)
fmt.Printf("%+v",host)
}
-------------------------------------------------------------
test.json
{
"hosts": {
"database": {
"address": "10.0.0.9",
"port": 3340
},
"cache": {
"address": "10.1.1.2",
"port": 63579
}
}
}
printfcoder commented
sidazhang123 commented
多谢第二个简单示例的参考,然而最终问题在保存。。goland保存了,而程序无法检测到,但notepad的就可以。micro的应该是监听signal的吧,看来这种方式可能出问题哦。