Documentation
¶
Index ¶
- Variables
- type FSStack
- type Watcher
- func NewCryptographicWatcher(filePath string, interval time.Duration) (*Watcher, error)
- func NewSimpleWatcher(filePath string, interval time.Duration) (*Watcher, error)
- func NewWatcher(filePath string, interval time.Duration, checks ...WatcherCheck) (*Watcher, error)
- func NewWatcherWithOpts(filePath string, opts WatcherOpts, interval time.Duration, ...) (*Watcher, error)
- type WatcherCheck
- type WatcherEvent
- type WatcherOpts
Constants ¶
This section is empty.
Variables ¶
var DefaultWatcherOpts = WatcherOpts{ FollowSymlinks: false, }
DefaultWatcherOpts is used when creating the Watcher without giving options
Functions ¶
This section is empty.
Types ¶
type FSStack ¶ added in v2.18.0
FSStack represents layers of fs.FS to open a file from. The first layer (starting at index 0, going up) responding other than fs.ErrNotExist will determine the response of this stack.
type Watcher ¶
type Watcher struct { C <-chan WatcherEvent CheckInterval time.Duration Err error FilePath string // contains filtered or unexported fields }
Watcher creates a background routine and emits events when the watched file changes on its C channel. If an error occurs the loop is stopped and the error is exposed on the Err property.
func NewCryptographicWatcher ¶
NewCryptographicWatcher is a wrapper around NewWatcher to configure the Watcher with presence and sha256 hash checks.
func NewSimpleWatcher ¶
NewSimpleWatcher is a wrapper around NewWatcher to configure the Watcher with presence, size and mtime checks.
func NewWatcher ¶
NewWatcher creates a new Watcher configured with the given filePath, default options, interval and checks given. The checks are executed once during initialization and will not cause an event to be sent. The created Watcher will automatically start its periodic check and the C channel should immediately be watched for changes. If the channel is not listened on the check loop will be paused until events are retrieved. If during the initial checks an error is detected the loop is NOT started and the watcher needs to be initialized again.
func NewWatcherWithOpts ¶ added in v2.16.0
func NewWatcherWithOpts(filePath string, opts WatcherOpts, interval time.Duration, checks ...WatcherCheck) (*Watcher, error)
NewWatcherWithOpts creates a new Watcher configured with the given filePath, options, interval and checks given. The checks are executed once during initialization and will not cause an event to be sent. The created Watcher will automatically start its periodic check and the C channel should immediately be watched for changes. If the channel is not listened on the check loop will be paused until events are retrieved. If during the initial checks an error is detected the loop is NOT started and the watcher needs to be initialized again.
type WatcherCheck ¶
type WatcherCheck func(*Watcher) (WatcherEvent, error)
WatcherCheck is an interface to implement own checks
func WatcherCheckHash ¶
func WatcherCheckHash(hcf func() hash.Hash) WatcherCheck
WatcherCheckHash returns a WatcherCheck configured with the given hash method (i.e. provide md5.New, sha1.New, ...). If the file is not present at the time of the check the check is skipped and will NOT cause an error.
type WatcherEvent ¶
type WatcherEvent uint
WatcherEvent is the detected change to be signeld through the channel within the Watcher
const ( WatcherEventInvalid WatcherEvent = iota WatcherEventNoChange WatcherEventFileAppeared WatcherEventFileModified WatcherEventFileVanished )
func WatcherCheckMtime ¶
func WatcherCheckMtime(w *Watcher) (WatcherEvent, error)
WatcherCheckMtime checks whether the mtime attribute of the file has changed. If the file is not present at the time of the check the check is skipped and will NOT cause an error.
func WatcherCheckPresence ¶
func WatcherCheckPresence(w *Watcher) (WatcherEvent, error)
WatcherCheckPresence simply checks whether the file is present and allows to emit WatcherEventFileAppeared / WatcherEventFileVanished events when the file existence state changes.
func WatcherCheckSize ¶
func WatcherCheckSize(w *Watcher) (WatcherEvent, error)
WatcherCheckSize checks whether the size of the file has changed. If the file is not present at the time of the check the check is skipped and will NOT cause an error.
type WatcherOpts ¶ added in v2.16.0
type WatcherOpts struct { // FollowSymlinks switches watchers based on file metadata into // a mode where they follow a symlink and check the real target // file instead of the symlink FollowSymlinks bool }
WatcherOpts holds configuration for newly created watcher