Documentation ¶
Overview ¶
Package gfsnotify 提供了一个跨平台的文件系统通知接口。
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 RemoveCallback ¶
RemoveCallback 从观察者中移除具有给定id的指定回调函数。
Types ¶
type Callback ¶
type Callback struct { Id int // 唯一标识回调对象的ID。 Func func(event *Event) // 回调函数。 Path string // 绑定文件路径(绝对路径)。 // contains filtered or unexported fields }
Callback是Watcher的回调函数。
func Add ¶
func Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
Add 使用默认观察器监控`path`,并使用回调函数`callbackFunc`。 可选参数`recursive`指定了是否递归地监控`path`,默认为true。
func AddOnce ¶
func AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
AddOnce 使用默认的监视器,通过回调函数 `callbackFunc` 仅对 `path` 进行一次性监控,并使用唯一的名称 `name` 标识。 如果多次调用 AddOnce 并传入相同的 `name` 参数,`path` 只会被添加监控一次。如果两次调用时使用了相同的 `name`,将会返回错误。
可选参数 `recursive` 指定是否递归地监控 `path`,默认情况下其值为 true。
type Event ¶
type Event struct { Path string // 绝对文件路径。 Op Op // File operation. Watcher *Watcher // Parent watcher. // contains filtered or unexported fields }
Event 是由底层 fsnotify 产生的事件。
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher 是用于文件变化监测的监视器。
func (*Watcher) Add ¶
func (w *Watcher) Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
添加监控,将回调函数`callbackFunc`添加到watcher中,并监控路径`path`。 可选参数`recursive`指定了是否递归地监控路径`path`,默认为true。
func (*Watcher) AddOnce ¶
func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error)
AddOnce 通过唯一名称 `name` 使用回调函数 `callbackFunc` 仅对 `path` 进行一次性监控。 如果多次调用 AddOnce 并传入相同的 `name` 参数,`path` 只会被添加一次进行监控。
若同一 `name` 被调用两次,将会返回错误。
可选参数 `recursive` 指定是否递归地监控 `path`,默认情况下其值为 true。
func (*Watcher) RemoveCallback ¶
RemoveCallback 从 watcher 中移除具有给定回调 id 的回调函数。