filenotify

package
v0.0.0-...-89dfdfc Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package filenotify provides a mechanism for watching file(s) for changes. Generally leans on fsnotify, but provides a poll-based notifier which fsnotify does not support. These are wrapped up in a common interface so that either can be used interchangeably in your code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilePoller

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

FilePoller is used to poll files for changes, especially in cases where fsnotify can't be run (e.g. when inotify handles are exhausted) FilePoller satisfies the FileWatcher interface

func (*FilePoller) Add

func (w *FilePoller) Add(name string) error

Add adds a filename to the list of watches once added the file is polled for changes in a separate goroutine

func (*FilePoller) Close

func (w *FilePoller) Close() error

Close closes the poller All watches are stopped, removed, and the poller cannot be added to

func (*FilePoller) Errors

func (w *FilePoller) Errors() <-chan error

Errors returns the errors channel This is used for notifications about errors on watched files

func (*FilePoller) Events

func (w *FilePoller) Events() <-chan fsnotify.Event

Events returns the event channel This is used for notifications on events about watched files

func (*FilePoller) Remove

func (w *FilePoller) Remove(name string) error

Remove stops and removes watch with the specified name

type FileWatcher

type FileWatcher interface {
	Events() <-chan fsnotify.Event
	Errors() <-chan error
	Add(name string) error
	Remove(name string) error
	Close() error
}

FileWatcher is an interface for implementing file notification watchers

func New

func New() (FileWatcher, error)

New tries to use an fs-event watcher, and falls back to the poller if there is an error

func NewEventWatcher

func NewEventWatcher() (FileWatcher, error)

NewEventWatcher returns an fs-event based file watcher

func NewPollingWatcher

func NewPollingWatcher() FileWatcher

NewPollingWatcher returns a poll-based file watcher

Jump to

Keyboard shortcuts

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