Commit b582452 1 parent 4794590 commit b582452 Copy full SHA for b582452
File tree 1 file changed +61
-0
lines changed
1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ # rnotify
2
+
3
+ ![ Build Status] ( https://github.com/y-yagi/rnotify/workflows/CI/badge.svg )
4
+
5
+ ` rnotify ` is a wrapper of [ fsnotify] ( https://github.com/fsnotify/fsnotify ) , supports recursive directory watching on Go.
6
+
7
+ ## Supported Platforms
8
+
9
+ Linux, Windows and macOS.
10
+
11
+ ## Usage
12
+
13
+ ``` go
14
+ package main
15
+
16
+ import (
17
+ " log"
18
+
19
+ " github.com/fsnotify/fsnotify"
20
+ " github.com/y-yagi/rnotify"
21
+ )
22
+
23
+ func main () {
24
+ watcher , err := rnotify.NewWatcher ()
25
+ if err != nil {
26
+ log.Fatal (err)
27
+ }
28
+ defer watcher.Close ()
29
+
30
+ done := make (chan bool )
31
+
32
+ go func () {
33
+ for {
34
+ select {
35
+ case event , ok := <- watcher.Events :
36
+ if !ok {
37
+ return
38
+ }
39
+ log.Println (" event:" , event)
40
+ // `Op` is the same as `fsnotify.Op`.
41
+ if event.Op &fsnotify.Write == fsnotify.Write {
42
+ log.Println (" modified file:" , event.Name )
43
+ }
44
+ case err , ok := <- watcher.Errors :
45
+ if !ok {
46
+ return
47
+ }
48
+ log.Println (" error:" , err)
49
+ }
50
+ }
51
+ }()
52
+
53
+ err = watcher.Add (" /tmp/foo" )
54
+ if err != nil {
55
+ log.Fatal (err)
56
+ }
57
+
58
+ <- done
59
+ }
60
+
61
+ ```
You can’t perform that action at this time.
0 commit comments