gfsnotify

package
v1.16.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2022 License: MIT Imports: 18 Imported by: 27

Documentation

Overview

Package gfsnotify provides a platform-independent interface for file system notifications.

Index

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 Remove

func Remove(path string) error

Remove removes all monitoring callbacks of given `path` from watcher recursively.

func RemoveCallback

func RemoveCallback(callbackId int) error

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 added in v1.10.0

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.

func (*Event) IsChmod

func (e *Event) IsChmod() bool

IsChmod checks whether current event contains file/folder chmod event.

func (*Event) IsCreate

func (e *Event) IsCreate() bool

IsCreate checks whether current event contains file/folder create event.

func (*Event) IsRemove

func (e *Event) IsRemove() bool

IsRemove checks whether current event contains file/folder remove event.

func (*Event) IsRename

func (e *Event) IsRename() bool

IsRename checks whether current event contains file/folder rename event.

func (*Event) IsWrite

func (e *Event) IsWrite() bool

IsWrite checks whether current event contains file/folder write event.

func (*Event) String

func (e *Event) String() string

String returns current event as string.

type Op

type Op uint32

Op is the bits union for file operations.

const (
	CREATE Op = 1 << iota
	WRITE
	REMOVE
	RENAME
	CHMOD
)

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher is the monitor for file changes.

func New

func New() (*Watcher, error)

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 added in v1.10.0

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) Close

func (w *Watcher) Close()

Close closes the watcher.

func (*Watcher) Remove

func (w *Watcher) Remove(path string) error

Remove removes monitor and all callbacks associated with the `path` recursively.

func (*Watcher) RemoveCallback

func (w *Watcher) RemoveCallback(callbackId int)

RemoveCallback removes callback with given callback id from watcher.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL