Help us shape the future of Go! Take the 2026 Go Developer Survey

watcher

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package watcher detects changes to protected files.

Editors save atomically (write temp file + rename), which drops watches on the file itself, so we watch parent directories, filter by name and debounce (~500ms) before hashing and creating a revision.

Package watcher turns filesystem events on protected files into sealed revisions, automatically.

Editors save atomically (write a temp file, rename it over the original), which drops a watch on the file itself. So we watch each protected file's *parent directory*, filter events by name, and debounce bursts of events before snapshotting. A periodic reconcile catches anything missed (e.g. events dropped while the machine slept) and picks up newly protected files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Debounce  time.Duration // quiet period after the last event (default 500ms)
	Reload    time.Duration // how often to re-read the protected file list (default 10s)
	Reconcile time.Duration // full snapshot of everything (default 5m)

	// OnSnapshot is called for each file that got a new revision or problem.
	OnSnapshot func(vault.SnapshotResult)
	// OnError reports non-fatal errors (a directory that can't be watched…).
	OnError func(error)
}

Options tune the watcher. Zero values get sensible defaults.

type Watcher

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

Watcher watches protected files and snapshots them on change.

func New

func New(v *vault.Vault, opts Options) (*Watcher, error)

New creates a watcher for v. Call Run to start it.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

Run blocks until ctx is cancelled. It first snapshots everything, to catch changes made while the daemon wasn't running.

func (*Watcher) Watching

func (w *Watcher) Watching() []string

Watching returns the currently watched files (sorted), for status output.

Jump to

Keyboard shortcuts

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