Documentation ¶
Overview ¶
Package watcher provides file update notification functionality as a module.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrMissingWithTarget = fmt.Errorf("watcher.Watcher missing or empty WithTarget option") ErrMissingWithFunc = fmt.Errorf("watcher.Watcher missing WithFunc option") )
Functions ¶
This section is empty.
Types ¶
type Opt ¶
func WithTarget ¶
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
func New ¶
New creates watcher with given options. WithTarget and WithFunc options are mandatory.
Example ¶
tmpFile, err := os.CreateTemp("", testFilePattern) if err != nil { fmt.Println(err) return } defer os.Remove(tmpFile.Name()) t := ticker.New( ticker.WithInterval(time.Second), ticker.WithFunc(func() error { _, err = tmpFile.Write([]byte("updated")) if err != nil { return err } return nil }), ) w := watcher.New( watcher.WithTarget(tmpFile.Name()), watcher.WithFunc(func() error { slog.Info("Hello from watcher") return errors.New("watcher error") }), ) err = service.Run(service.Modules{t, w}) if err != nil { fmt.Println(err) }
Output: 1 error occurred: * failed to run module watcher.Watcher: watcher error
Click to show internal directories.
Click to hide internal directories.