watcher

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WalkDirectoryForFiles

func WalkDirectoryForFiles(dir string, validExts, excludeDirs []string) (files []string, err error)

WalkDirectoryForFiles discovers all subdirectories and returns a list of valid files in them

Types

type FileEvent

type FileEvent byte

FileEvent is an enum describing a change in a file's state

const (
	FileEventNone   FileEvent = iota // 0
	FileEventModify                  // 1
	FileEventDelete                  // 2
	FileEventMove                    // 3
)

func (FileEvent) String

func (e FileEvent) String() string

type FileEvents

type FileEvents []FileEvent

FileEvents is a slice of FileEvents

func (FileEvents) Bytes

func (e FileEvents) Bytes() []byte

func (FileEvents) String

func (e FileEvents) String() string

type FileUpdate

type FileUpdate struct {
	Event FileEvent
	Path  string
}

FileUpdate is used by watchers to signal the state change of a file.

type FileUpdateStream

type FileUpdateStream chan *FileUpdate

type FileUpdates

type FileUpdates []*FileUpdate

FileUpdates is a slice of FileUpdate pointers

type FileWatcher

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

FileWatcher recursively monitors changes in files in the given directory and sends out events based on their state changes. Only files conforming to validSuffix are monitored. The FileWatcher can be suspended for a single event at a time to eliminate updates by WatchStorage causing a loop.

func NewFileWatcher

func NewFileWatcher(dir string) (w *FileWatcher, files []string, err error)

NewFileWatcher returns a list of files in the watched directory in addition to the generated FileWatcher, it can be used to populate MappedRawStorage fileMappings

func NewFileWatcherWithOptions

func NewFileWatcherWithOptions(dir string, opts Options) (w *FileWatcher, files []string, err error)

NewFileWatcher returns a list of files in the watched directory in addition to the generated FileWatcher, it can be used to populate MappedRawStorage fileMappings

func (*FileWatcher) Close

func (w *FileWatcher) Close()

Close closes active underlying resources

func (*FileWatcher) GetFileUpdateStream

func (w *FileWatcher) GetFileUpdateStream() FileUpdateStream

GetFileUpdateStream gets the channel with FileUpdates

func (*FileWatcher) Suspend

func (w *FileWatcher) Suspend(updateEvent FileEvent)

Suspend enables a one-time suspend of the given event, the FileWatcher will skip the given event once

type Options

type Options struct {
	// ExcludeDirs specifies what directories to not watch
	ExcludeDirs []string
	// BatchTimeout specifies the duration to wait after last event before dispatching grouped inotify events
	BatchTimeout time.Duration
	// ValidExtensions specifies what file extensions to look at
	ValidExtensions []string
}

Options specifies options for the FileWatcher

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the default options

Jump to

Keyboard shortcuts

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