Add a file listener

This commit is contained in:
Aaron Fischer 2016-07-05 00:20:17 +02:00
commit 589bb9d144
1 changed files with 43 additions and 0 deletions

43
agent.go Normal file
View File

@ -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()
}