Documentation ¶
Overview ¶
Package fsnotify provides a platform-independent interface for file system notifications.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶ added in v1.0.0
type Event struct { Name string // Relative path to the file or directory. Op Op // File operation that triggered the event. }
Event represents a single file system notification.
type Watcher ¶
type Watcher struct { Events chan Event Errors chan error // contains filtered or unexported fields }
Watcher watches a set of files, delivering events to a channel.
func NewWatcher ¶
NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.
Example ¶
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:
func (*Watcher) Add ¶ added in v1.0.0
Add starts watching the named file or directory (non-recursively).
Click to show internal directories.
Click to hide internal directories.