From 4ebc8d6a1487c1e32e82dad511f652514b3b79d3 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 8 Jul 2021 00:21:40 +0800 Subject: [PATCH] fix skip condition --- cmd/svc/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/svc/main.go b/cmd/svc/main.go index b1379a6..003792e 100644 --- a/cmd/svc/main.go +++ b/cmd/svc/main.go @@ -54,10 +54,17 @@ func main() { // channel closed return } - if event.Op&fsnotify.Write == fsnotify.Write { + // 改成有變動就reload + if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Chmod == fsnotify.Chmod { // send reload channel reloadChan <- struct{}{} } + if event.Op&fsnotify.Remove == fsnotify.Remove { + watcher.Remove(cfgPath) + if err := watcher.Add(cfgPath); err != nil { + log.Fatal(err) + } + } case err, ok := <-watcher.Errors: if !ok { // channel closed @@ -113,8 +120,8 @@ func runService(reload <-chan struct{}) { } return } - if time.Since(lastReload).Seconds() < float64(2*time.Second) { - break + if time.Since(lastReload).Seconds() < (2 * time.Second).Seconds() { + continue } lastReload = time.Now() -- 2.45.2