Browse Source

Add a file listener

master
Aaron Fischer 6 years ago
commit
589bb9d144
  1. 43
      agent.go

43
agent.go

@ -0,0 +1,43 @@
package main
import (
"fmt"
"log"
"github.com/fsnotify/fsnotify"
)
func watchForConfigChanges() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event := <-watcher.Events:
log.Println("event: ", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err := <-watcher.Errors:
log.Println("error:", err)
}
}
}()
// TODO: Add working directory
err = watcher.Add("/tmp/test")
if err != nil {
log.Fatal(err)
}
<-done
}
func main() {
fmt.Printf("Ready\n")
watchForConfigChanges()
}