Documentation ¶
Overview ¶
Package gfsnotify provides a platform-independent interface for file system notifications.
Index ¶
- func Exit()
- func Remove(path string) error
- func RemoveCallback(callbackId int) error
- type Callback
- type Event
- type Op
- type Watcher
- func (w *Watcher) Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
- func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
- func (w *Watcher) Close()
- func (w *Watcher) Remove(path string) error
- func (w *Watcher) RemoveCallback(callbackId int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exit ¶
func Exit()
Exit is only used in the callback function, which can be used to remove current callback of itself from the watcher.
func RemoveCallback ¶
RemoveCallback removes specified callback with given id from watcher.
Types ¶
type Callback ¶
type Callback struct { Id int // Unique id for callback object. Func func(event *Event) // Callback function. Path string // Bound file path (absolute). // contains filtered or unexported fields }
Callback is the callback function for Watcher.
func Add ¶
func Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
Add monitors `path` using default watcher with callback function `callbackFunc`. The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.
func AddOnce ¶
func AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
AddOnce monitors `path` using default watcher with callback function `callbackFunc` only once using unique name `name`. If AddOnce is called multiple times with the same `name` parameter, `path` is only added to monitor once. It returns error if it's called twice with the same `name`.
The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.
type Event ¶
type Event struct { Path string // Absolute file path. Op Op // File operation. Watcher *Watcher // Parent watcher. // contains filtered or unexported fields }
Event is the event produced by underlying fsnotify.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher is the monitor for file changes.
func New ¶
New creates and returns a new watcher. Note that the watcher number is limited by the file handle setting of the system. Eg: fs.inotify.max_user_instances system variable in linux systems.
func (*Watcher) Add ¶
func (w *Watcher) Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
Add monitors `path` with callback function `callbackFunc` to the watcher. The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.
func (*Watcher) AddOnce ¶
func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
AddOnce monitors `path` with callback function `callbackFunc` only once using unique name `name` to the watcher. If AddOnce is called multiple times with the same `name` parameter, `path` is only added to monitor once.
It returns error if it's called twice with the same `name`.
The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.
func (*Watcher) Remove ¶
Remove removes monitor and all callbacks associated with the `path` recursively.
func (*Watcher) RemoveCallback ¶
RemoveCallback removes callback with given callback id from watcher.