filewatcher

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileWatcher

type FileWatcher struct {
	sync.Mutex

	// the interval that we will check the existence of the file again
	// default = 5s, can be adjustable, especially for unittests
	CheckFileInterval time.Duration
	// contains filtered or unexported fields
}

FileWatcher is a helper struct that helps us watching a file event if the file does't exist yet

func New

func New(
	filePath string,
	onChangeHandler func(f *FileWatcher, event fsnotify.Event),
	onErrorHandler func(f *FileWatcher, err error) bool,
) (*FileWatcher, error)

Create new watcher for a file with some pre-defined handlers

func (*FileWatcher) FileExist

func (f *FileWatcher) FileExist() bool

the watched file exists ot not?

func (*FileWatcher) InWatchedQueue

func (f *FileWatcher) InWatchedQueue() bool

is the file in the watched queue?

func (*FileWatcher) SetFileExist

func (f *FileWatcher) SetFileExist(value bool)

set the existence of the watched file

func (*FileWatcher) SetInWatchedQueue

func (f *FileWatcher) SetInWatchedQueue(value bool)

update the status of the file in the watched queue

func (*FileWatcher) Watch

func (f *FileWatcher) Watch(ctx context.Context)

Start watching the file Even when the file is deleted and re-created, the watcher can still put an eye on it until the context is done

Jump to

Keyboard shortcuts

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