]> go.fuhry.dev Git - fsnotify.git/commitdiff
update example
authorNathan Youngman <git@nathany.com>
Sat, 5 Jul 2014 03:03:05 +0000 (21:03 -0600)
committerNathan Youngman <git@nathany.com>
Sat, 5 Jul 2014 03:03:24 +0000 (21:03 -0600)
README.md
example_test.go

index c52e6d5edb935c4dc7f029de62a66bd33e98e9c1..f8e0c9695b8d9532dfb0ebb7c489dd9ee1b1f067 100644 (file)
--- 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).
index 5b420ccb3209856b9ec41bf1964349027aed6113..75261fbfb30d9fc2a1113523403e7043ded838d5 100644 (file)
@@ -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)
                        }