Documentation ¶
Index ¶
- Variables
- type Event
- type FilterFileHookFunc
- type Op
- type Watcher
- func (w *Watcher) Add(name string) (err error)
- func (w *Watcher) AddFilterHook(f FilterFileHookFunc)
- func (w *Watcher) AddRecursive(name string) (err error)
- func (w *Watcher) Close()
- func (w *Watcher) FilterOps(ops ...Op)
- func (w *Watcher) Ignore(paths ...string) (err error)
- func (w *Watcher) IgnoreHiddenFiles(ignore bool)
- func (w *Watcher) Remove(name string) (err error)
- func (w *Watcher) RemoveRecursive(name string) (err error)
- func (w *Watcher) SetMaxEvents(delta int)
- func (w *Watcher) Start(d time.Duration) error
- func (w *Watcher) TriggerEvent(eventType Op, file os.FileInfo)
- func (w *Watcher) Wait()
- func (w *Watcher) WatchedFiles() map[string]os.FileInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDurationTooShort occurs when calling the watcher's Start // method with a duration that's less than 1 nanosecond. ErrDurationTooShort = errors.New("error: duration is less than 1ns") // ErrWatcherRunning occurs when trying to call the watcher's // Start method and the polling cycle is still already running // from previously calling Start and not yet calling Close. ErrWatcherRunning = errors.New("error: watcher is already running") // ErrWatchedFileDeleted is an error that occurs when a file or folder that was // being watched has been deleted. ErrWatchedFileDeleted = errors.New("error: watched file or folder deleted") // ErrSkip is less of an error, but more of a way for path hooks to skip a file or // directory. ErrSkip = errors.New("error: skipping file") )
Functions ¶
This section is empty.
Types ¶
type Event ¶
An Event describes an event that is received when files or directory changes occur. It includes the os.FileInfo of the changed file or directory and the type of event that's occurred and the full path of the file.
type FilterFileHookFunc ¶ added in v1.0.5
FilterFileHookFunc is a function that is called to filter files during listings. If a file is ok to be listed, nil is returned otherwise ErrSkip is returned.
func RegexFilterHook ¶ added in v1.0.5
func RegexFilterHook(r *regexp.Regexp, useFullPath bool) FilterFileHookFunc
RegexFilterHook is a function that accepts or rejects a file for listing based on whether it's filename or full path matches a regular expression.
type Op ¶
type Op uint32
An Op is a type that is used to describe what type of event has occurred during the watching process.
type Watcher ¶
type Watcher struct { Event chan Event Error chan error Closed chan struct{} // contains filtered or unexported fields }
Watcher describes a process that watches files for changes.
func (*Watcher) AddFilterHook ¶ added in v1.0.5
func (w *Watcher) AddFilterHook(f FilterFileHookFunc)
AddFilterHook
func (*Watcher) AddRecursive ¶
AddRecursive adds either a single file or directory recursively to the file list.
func (*Watcher) Close ¶
func (w *Watcher) Close()
Close stops a Watcher and unlocks its mutex, then sends a close signal.
func (*Watcher) FilterOps ¶
FilterOps filters which event op types should be returned when an event occurs.
func (*Watcher) Ignore ¶
Ignore adds paths that should be ignored.
For files that are already added, Ignore removes them.
func (*Watcher) IgnoreHiddenFiles ¶
IgnoreHiddenFiles sets the watcher to ignore any file or directory that starts with a dot.
func (*Watcher) RemoveRecursive ¶
RemoveRecursive removes either a single file or a directory recursively from the file's list.
func (*Watcher) SetMaxEvents ¶
SetMaxEvents controls the maximum amount of events that are sent on the Event channel per watching cycle. If max events is less than 1, there is no limit, which is the default.
func (*Watcher) Start ¶
Start begins the polling cycle which repeats every specified duration until Close is called.
func (*Watcher) TriggerEvent ¶
TriggerEvent is a method that can be used to trigger an event, separate to the file watching process.