file

package
v2.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type FSStack []fs.FS

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.

func (FSStack) Open added in v2.18.0

func (f FSStack) Open(name string) (fs.File, error)

Open iterates the FSStack starting at index 0, going up and returns the first non fs.ErrNotExist response. If all layers responds with fs.ErrNotExist a fs.PathError wrapping fs.ErrNotExist is returned.

func (FSStack) ReadFile added in v2.18.0

func (f FSStack) ReadFile(name string) ([]byte, error)

ReadFile is a convenice wrapper around Open and returns the content of the file if any is available.

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

func NewCryptographicWatcher(filePath string, interval time.Duration) (*Watcher, error)

NewCryptographicWatcher is a wrapper around NewWatcher to configure the Watcher with presence and sha256 hash checks.

func NewSimpleWatcher

func NewSimpleWatcher(filePath string, interval time.Duration) (*Watcher, error)

NewSimpleWatcher is a wrapper around NewWatcher to configure the Watcher with presence, size and mtime checks.

func NewWatcher

func NewWatcher(filePath string, interval time.Duration, checks ...WatcherCheck) (*Watcher, error)

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.

func (*Watcher) GetState

func (w *Watcher) GetState(key string) any

GetState is a helper to retrieve state from the internal store for usage in checks to have their state retained.

func (*Watcher) SetState

func (w *Watcher) SetState(key string, value any)

SetState is a helper to set state into the internal store for usage in checks to have their state retained.

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

Jump to

Keyboard shortcuts

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