commit 589bb9d144229ae9cbaa498cd4efbb52668fd784 Author: Aaron Fischer Date: Tue Jul 5 00:20:17 2016 +0200 Add a file listener diff --git a/agent.go b/agent.go new file mode 100644 index 0000000..e9cb809 --- /dev/null +++ b/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() +}