func (h *Handler) watch() { specs, err := ReadSpecs(h.specfile) if err != nil { h.log(err) return } watcher, err := fsnotify.NewWatcher() if err != nil { h.log(err) return } defer watcher.Close() watcher.Watch(h.specfile) for _, s := range specs { for _, f := range s.Files { watcher.Watch(filepath.Join(h.dir, f)) } } select { case <-watcher.Event: case err := <-watcher.Error: h.log(err) return } time.Sleep(time.Second / 10) h.mend() h.OnChange() go h.watch() }
func ExampleNewWatcher() { watcher, err := fsnotify.NewWatcher() if err != nil { log.Fatal(err) } go func() { for { select { case ev := <-watcher.Event: log.Println("event:", ev) case err := <-watcher.Error: log.Println("error:", err) } } }() err = watcher.Watch("/tmp/foo") if err != nil { log.Fatal(err) } }