Created
August 13, 2012 01:33
-
-
Save davecheney/3336284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/howeyc/fsnotify" | |
"log" | |
) | |
func main() { | |
watcher, err := fsnotify.NewWatcher() | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = watcher.Watch("/tmp") | |
if err != nil { | |
log.Fatal(err) | |
} | |
for { | |
select { | |
case ev := <-watcher.Event: | |
log.Println("event:", ev) | |
case err := <-watcher.Error: | |
log.Println("error:", err) | |
} | |
} | |
} |
Here's the full code including main
, there may be an error, I couldn't test it as I'm reinstalling my system and don't have a compiler at hand.
package main
import (
"log"
"github.com/howeyc/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
go func() {
for {
// For some reason this select statement
// is ignored
select {
case ev := <-watcher.Event:
log.Println(ev)
case err := <-watcher.Error:
log.Println(err)
}
}
}()
if err = watcher.Watch("some-file-here"); err != nil {
log.Fatal(err)
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what I'm doing now for my program github.com/larzconwell/gwatch
The example shows this though: