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 WatchOption
- type Watcher
- func (w *Watcher) Add(path string, callbackFunc func(event *Event), option ...WatchOption) (callback *Callback, err error)
- func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), option ...WatchOption) (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), option ...WatchOption) (callback *Callback, err error)
Add monitors `path` using default watcher with callback function `callbackFunc`.
The parameter `path` can be either a file or a directory path. 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), option ...WatchOption) (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 parameter `path` can be either a file or a directory path. 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 WatchOption ¶ added in v2.7.8
type WatchOption struct { // NoRecursive explicitly specifies no recursive watching. // Recursive watching will also watch all its current and following created subfolders and sub-files. // // Note that the recursive watching is enabled in default. NoRecursive bool }
WatchOption holds the option for watching.
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. Example: fs.inotify.max_user_instances system variable in linux systems.
In most case, you can use the default watcher for usage instead of creating one.
func (*Watcher) Add ¶
func (w *Watcher) Add( path string, callbackFunc func(event *Event), option ...WatchOption, ) (callback *Callback, err error)
Add monitors `path` with callback function `callbackFunc` to the watcher.
The parameter `path` can be either a file or a directory path. 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), option ...WatchOption, ) (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 parameter `path` can be either a file or a directory path. The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default.
func (*Watcher) Remove ¶
Remove removes watching and all callbacks associated with the `path` recursively. Note that, it's recursive in default if given `path` is a directory.
func (*Watcher) RemoveCallback ¶
RemoveCallback removes callback with given callback id from watcher.
Note that, it auto removes the path watching if there's no callback bound on it.