Documentation
¶
Overview ¶
Package watch polls a single file and reports content changes via a callback.
It is an operator convenience that lets the gateway pick up an in-place edit to its configuration file without an explicit SIGHUP. The package is a leaf of the import graph: it imports only the standard library and knows nothing about configuration or the gateway. It detects that a file changed and invokes a caller-supplied callback, leaving the meaning of a reload to the caller. Change is judged by the file's modification time and size, which covers both in-place edits and the atomic write-temp-then-rename-over pattern (the replacement file carries a fresh modification time).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher polls a file and calls onChange whenever the file's modification time or size changes after Run begins.
func New ¶
New returns a Watcher that polls path every interval and calls onChange after each detected change. interval must be positive; the caller (cmd) validates it before constructing the Watcher.
func (*Watcher) Run ¶
Run polls the file until ctx is cancelled, then returns. It captures a baseline at start so the first poll never fires a spurious change; thereafter it fires onChange once per detected change. A transient not-exist is ignored (the baseline is held until the file reappears); any other stat error is logged once per error episode and never fires onChange or stops the loop.
onChange runs synchronously on the polling goroutine, so it must not block: a slow callback stalls polling and delays observing ctx cancellation. Callers are expected to hand off (e.g. a non-blocking send) rather than do work inline.