update watcher

This commit is contained in:
yuzuki999 2023-04-07 13:11:56 +08:00
parent e20c9b9290
commit 7d1b916bac
2 changed files with 8 additions and 9 deletions

View File

@ -56,16 +56,14 @@ func (p *Conf) Watch(filePath string, reload func()) error {
for {
select {
case event := <-watcher.Events:
if event.Op&fsnotify.Chmod == fsnotify.Chmod {
if event.Name == filePath {
log.Println("config file changed, reloading...")
err := p.LoadFromPath(filePath)
if err != nil {
log.Printf("reload config error: %s", err)
}
log.Println("reload config success")
reload()
if event.Has(fsnotify.Write) {
log.Println("config dir changed, reloading...")
err := p.LoadFromPath(filePath)
if err != nil {
log.Printf("reload config error: %s", err)
}
log.Println("reload config success")
reload()
}
case err := <-watcher.Errors:
if err != nil {

1
conf/conf_test.go Normal file
View File

@ -0,0 +1 @@
package conf