package fsnotify
import "github.com/tilt-dev/fsnotify"
Package fsnotify provides a platform-independent interface for file system notifications.
Index ¶
Examples ¶
Variables ¶
Common errors that can be reported by a watcher
Types ¶
type Event ¶
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.
func (Event) String ¶
String returns a string representation of the event in the form "file: REMOVE|WRITE|..."
type Op ¶
type Op uint32
Op describes a set of file operations.
These are the generalized file operations that can trigger a notification.
func (Op) String ¶
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.
Code:play
Example¶
package main
import (
"log"
"github.com/fsnotify/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
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)
}
<-done
}
func (*Watcher) Add ¶
Add starts watching the named file or directory (non-recursively).
func (*Watcher) Close ¶
Close removes all watches and closes the events channel.
func (*Watcher) Remove ¶
Remove stops watching the named file or directory (non-recursively).
Source Files ¶
fsnotify.go inotify.go inotify_poller.go
- Version
- v1.4.7 (latest)
- Published
- Jan 10, 2018
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- now –
Tools for package owners.