From: Nathan Youngman Date: Sat, 5 Jul 2014 03:03:05 +0000 (-0600) Subject: update example X-Git-Tag: v1.7.2~296 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=1a4e092e987843a825b29733a430e12e4ef896d7;p=fsnotify.git update example --- diff --git a/README.md b/README.md index c52e6d5..f8e0c96 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,6 @@ A future version of Go will have [fsnotify in the standard library](https://code Please read [CONTRIBUTING](https://github.com/fsnotify/fsnotify/blob/master/CONTRIBUTING.md) before opening a pull request. +## Example + +See [example_test.go](https://github.com/fsnotify/fsnotify/blob/master/example_test.go). diff --git a/example_test.go b/example_test.go index 5b420cc..75261fb 100644 --- a/example_test.go +++ b/example_test.go @@ -17,12 +17,16 @@ func ExampleNewWatcher() { if err != nil { log.Fatal(err) } + defer watcher.Close() go func() { for { select { - case ev := <-watcher.Events: - log.Println("event:", ev) + 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) }