Documentation ¶
Overview ¶
Package fsnotify implements file system notification.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { Name string // Relative path to the file/directory. Op Op // Platform-independent bitmask. }
Event represents a single file system event.
type Watcher ¶
type Watcher struct { Errors chan error // Errors are sent on this channel Events chan Event // Events are returned on this channel // contains filtered or unexported fields }
func NewWatcher ¶
NewWatcher creates and returns a new inotify instance using inotify_init(2)
Example ¶
package main import ( "log" "github.com/go-fsnotify/fsnotify" ) func main() { watcher, err := fsnotify.NewWatcher() if err != nil { log.Fatal(err) } defer watcher.Close() 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) } } }() err = watcher.Add("/tmp/foo") if err != nil { log.Fatal(err) } }
Output:
Click to show internal directories.
Click to hide internal directories.