configx-watch

command
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 7 Imported by: 0

README

configx-watch

Demonstrates configx Watch hot reload.

Run from repository root:

go run ./examples/configx-watch

Expected output (timing may vary):

loaded config: log.level=info
watching log.level... (rewrite the file to trigger reload)
rewrote file: log.level=debug
reload detected: log.level=debug
done

The example writes a config file, loads it, registers a Watch callback on log.level, then rewrites the file to trigger a reload. The watcher (backed by fsnotify) detects the file change and fires the callback.

Watch contract:

  • Watch(key, observer) requires the key to exist at registration time.
  • Multiple observers per key are supported.
  • Observers fire synchronously inside Load; keep them short and non-blocking.
  • Use an atomic.Value to ferry the new value back to your application code.

For the full pattern (including WithResolveActualTypes, layered env override, and custom decoders), see configx/example_test.go and configx/example_business_test.go.

Documentation

Overview

Package main demonstrates configx Watch hot reload.

Run:

go run ./examples/configx-watch

The example writes a config file, loads it, registers a Watch callback on log.level, then rewrites the file to trigger a reload. The callback prints the new level.

Expected output (timing may vary):

loaded config: log.level=info
watching log.level... (rewrite the file to trigger reload)
rewrote file: log.level=debug
reload detected: log.level=debug
done

Jump to

Keyboard shortcuts

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