Documentation
¶
Overview ¶
Package watchdog provides a high-level file system event library. It wraps fsnotify with debouncing, glob pattern matching, recursive watching, and typed event dispatch.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWatcherClosed is returned when On() or Start() is called // after Stop() has been called. ErrWatcherClosed = errors.New("watchdog: watcher is closed") // ErrInvalidPattern is returned by On() when the glob pattern // is not valid syntax. ErrInvalidPattern = errors.New("watchdog: invalid glob pattern") // ErrPathNotFound is returned by Start() when a watched path // does not exist on disk. ErrPathNotFound = errors.New("watchdog: path does not exist") )
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// Path is the absolute path of the changed file.
Path string
// Op is the type of change that occurred.
Op Op
// Time is when the event was detected.
Time time.Time
// Size is the file size in bytes at the time of the event.
Size int64
}
Event represents a single file system change delivered to a handler.
type HandlerFunc ¶
type HandlerFunc func(Event)
HandlerFunc is the function signature for all event handlers. It receives an Event describing the file system change.
type Op ¶
type Op uint32
Op represents a file system operation as a bitmask. Multiple operations can be combined: Created | Modified.
Op constants represent the types of file system events.
type Option ¶
type Option func(*config)
Option is a functional option for configuring a Watcher.
func WithDebounce ¶
WithDebounce sets the debounce window — the quiet period after the last event before the handler is called. Default is 100ms.
func WithIgnore ¶
WithIgnore specifies glob patterns for directories to skip during recursive walking. Example: WithIgnore("vendor", ".git")
func WithRecursive ¶
WithRecursive controls whether subdirectories are watched automatically. Default is true.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches directories and files for changes, routing events to registered handlers. Create one with New(), register handlers with On(), then call Start() to begin watching.
func New ¶
New creates a Watcher with the given options. If no options are provided, sensible defaults are used: 100ms debounce window and recursive watching enabled.
func (*Watcher) On ¶
func (w *Watcher) On(op Op, pattern string, fn HandlerFunc) error
On registers fn to be called when a file matching pattern is changed with the given Op. Pattern supports glob syntax including ** for recursive matching. Returns ErrInvalidPattern if pattern is invalid. Returns ErrWatcherClosed if the watcher has been stopped.