watchf

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Path       string
	Content    string
	UpdateTime time.Time
	HandleTime time.Time
}

File represent a file found by Watcher in directories

type Option

type Option func(*Watcher)

Option for watcher

func WithContext

func WithContext(ctx context.Context) Option

WithContext set a context for watcher. watcher will automatically stopped when context was canceled

func WithDisableTemplate

func WithDisableTemplate(b bool) Option

WithDisableTemplate disable the template execution, watcher will parse the raw content in file to the Handler

func WithFileNameFilter

func WithFileNameFilter(f func(string) bool) Option

WithFileNameFilter used to ignore some files in directories. such as some big file.

func WithHandler

func WithHandler(h func(File)) Option

WithTemplateVars set the file handler for watcher. It will be called will file was changed or first found.

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval set the interval for detecting changes of files. 10 seconds by default.

func WithLogger

func WithLogger(f func(string, error)) Option

WithLogger customize the logger function

func WithTemplateFuncs

func WithTemplateFuncs(fs map[string]any) Option

WithTemplateVars customize the functions used to parse template

func WithTemplateVars

func WithTemplateVars(data any) Option

WithTemplateVars customize the variables used to parse template

type Watcher

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

Watcher watch the changes of files in given directories, and call the given handler for each files.

func New

func New(dirs []string, opts ...Option) *Watcher

New create a new Watcher for given directories

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop the watcher

func (*Watcher) Watch

func (w *Watcher) Watch()

Watch start to watch directories, it will block until Watcher.Stop() was invoked

Watcher can be reused after it, it means that you can Watch() again after it was Stopped

Jump to

Keyboard shortcuts

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