From 7d1b916bac1df0857a20c2db50bc22b410b41b82 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Fri, 7 Apr 2023 13:11:56 +0800 Subject: [PATCH] update watcher --- conf/conf.go | 16 +++++++--------- conf/conf_test.go | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 conf/conf_test.go diff --git a/conf/conf.go b/conf/conf.go index bc44712..e00b48b 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -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 { diff --git a/conf/conf_test.go b/conf/conf_test.go new file mode 100644 index 0000000..8f52a95 --- /dev/null +++ b/conf/conf_test.go @@ -0,0 +1 @@ +package conf