diff options
| author | davy wybiral <davy.wybiral@gmail.com> | 2019-07-03 14:44:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-03 14:44:31 -0500 |
| commit | 6b8d872d680d019827cc45881186cce3f83f764a (patch) | |
| tree | c62947428cf59bbf11e2bb9df5ac69355f919075 /pkg/app/app.go | |
| parent | deb6808c75b54ac23f3332ac32525b475dd267f3 (diff) | |
added debounce (#11)
Diffstat (limited to 'pkg/app/app.go')
| -rw-r--r-- | pkg/app/app.go | 24 |
1 files changed, 1 insertions, 23 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index baf3ccb..22ad91f 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -89,32 +89,10 @@ func (a *App) Run() error { } a.Watcher.Add(p.Path) } - go a.watch() + go startWatcher(a) return http.Serve(a.Listener, a.Router) } -// Watch the library path and update Library with changes. -func (a *App) watch() { - for { - e, ok := <-a.Watcher.Events - if !ok { - return - } - if e.Op&fsnotify.Create > 0 { - // add new files to library - a.Library.Add(e.Name) - } else if e.Op&(fsnotify.Write|fsnotify.Chmod) > 0 { - // writes and chmods should remove old file before adding again - a.Library.Remove(e.Name) - a.Library.Add(e.Name) - } else if e.Op&(fsnotify.Remove|fsnotify.Rename) > 0 { - // remove and rename just remove file - // fsnotify will signal a Create event with the new file name - a.Library.Remove(e.Name) - } - } -} - // HTTP handler for / func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) { log.Printf("/") |
