API Reference
Core Types
Section titled “Core Types”Watcher
Section titled “Watcher”The main type. Created with New(), implements io.Closer.
type Watcher struct { /* fields */ }Methods
Section titled “Methods”func New(paths []string, opts ...Option) (*Watcher, error)func (w *Watcher) Watch(ctx context.Context) (<-chan Event, error)func (w *Watcher) WatchOnce(ctx context.Context) (Event, error)func (w *Watcher) Add(path string) errorfunc (w *Watcher) AddRecursive(path string, maxDepth int) errorfunc (w *Watcher) Remove(path string) errorfunc (w *Watcher) WatchList() []stringfunc (w *Watcher) Stats() Statsfunc (w *Watcher) Errors() <-chan errorfunc (w *Watcher) IsClosed() boolfunc (w *Watcher) IsWatching() boolfunc (w *Watcher) Reset() errorfunc (w *Watcher) Close() errortype Event struct { Path string // Absolute path Op Op // Create, Write, Remove, or Rename Timestamp time.Time // When detected IsDir bool // True if directory Size int64 // File size in bytes ModTime time.Time // File modification time Hash string // SHA-256 hex (with WithContentHashing)}type Op int
const ( Create Op = 1 Write Op = 2 Remove Op = 3 Rename Op = 4)Event priority when multiple ops coalesce: Create > Write > Remove > Rename.
type Stats struct { WatchCount int IsWatching bool IsClosed bool EventsProcessed uint64 EventsFilteredOut uint64 ErrorsEncountered uint64 WatchErrors uint64 Uptime time.Duration WatchLimit int WatchBudgetUsed float64}Filters
Section titled “Filters”type Filter func(event Event) boolBuilt-in Filters
Section titled “Built-in Filters”FilterExtensions, FilterIgnoreExtensions, FilterIgnoreDirs, FilterExcludePaths, FilterIgnoreHidden, FilterIgnoreGlobs, FilterOperations, FilterNotOperations, FilterGlob, FilterRegex, FilterMinSize, FilterMaxSize, FilterMinAge, FilterModifiedSince, FilterContentHash, FilterGitignore, FilterGeneratedCode, FilterGeneratedCodeFull, FilterGeneratedCodeWithFilter
Combinators
Section titled “Combinators”FilterAnd, FilterOr, FilterNot
Metadata Filters
Section titled “Metadata Filters”FilterWithMeta, FilterFromWithMeta, FilterWithMetaAnd, FilterWithMetaOr, FilterWithMetaNot, WithMeta
Middleware
Section titled “Middleware”type Middleware func(Handler) Handlertype Handler func(ctx context.Context, event Event) errorBuilt-in Middleware
Section titled “Built-in Middleware”MiddlewareLogging, MiddlewareRecovery, MiddlewareFilter, MiddlewareOnError, MiddlewareRateLimit, MiddlewareSlidingWindowRateLimit, MiddlewareThrottle, MiddlewareMetrics, MiddlewareDeduplicate, MiddlewareBatch, MiddlewareWriteFileLog, MiddlewareCircuitBreaker, MiddlewareExponentialBackoff, MiddlewareErrorRateLimit, MiddlewareErrorRecovery, MiddlewareErrorCorrelation, MiddlewareErrorSanitization, MiddlewareErrorBatch
Options
Section titled “Options”24 functional options:
WithDebounce, WithPerPathDebounce, WithFilter, WithExtensions, WithIgnoreDirs, WithIgnoreHidden, WithIgnorePatterns, WithRecursive, WithMiddleware, WithErrorHandler, WithOnError, WithSkipDotDirs, WithBuffer, WithOnAdd, WithLazyIsDir, WithPolling, WithPollInterval, WithDebug, WithFollowSymlinks, WithGitignore, WithExcludePaths, WithMaxWatches, WithContentHashing, WithSelfHeal
Error Handling
Section titled “Error Handling”Sentinel Errors
Section titled “Sentinel Errors”ErrWatcherClosed, ErrNoPaths, ErrPathNotFound, ErrPathNotDir, ErrWatcherRunning, ErrUnknownOp, ErrFsnotifyFailed, ErrWalkFailed, ErrPathResolveFailed, ErrEventProcessingFailed, ErrMiddlewareFailed
WatcherError
Section titled “WatcherError”type WatcherError struct { Op OpString Path string Err error Category ErrorCategory Stack []byte}Methods: Error(), Unwrap(), IsTransient(), IsPermanent(), Code()
Full API on pkg.go.dev
Section titled “Full API on pkg.go.dev”For the complete, always-up-to-date API documentation, see pkg.go.dev.