reload

command
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

README ΒΆ

Hot Reload Example

This example demonstrates cross-platform configuration hot reloading using FileWatchSource.

What It Does

  • Watches config.json for changes
  • Automatically reloads configuration when the file is saved
  • No restart required β€” the application continues running
  • Works on Windows, Linux, and macOS

Running the Example

cd examples/reload
go run main.go

You should see:

=== Hot Reload Example (Cross-Platform) ===

βœ… Configuration loaded: {AppName:LifecycleDemo Debug:true Port:8080 Message:Hello from lifecycle hot reload!}

✨ App started with hot reload enabled!
   Edit config.json to see configuration reload in real-time
   Press Ctrl+C to exit

πŸ“Š LifecycleDemo running on port 8080 (debug=true): Hello from lifecycle hot reload!

Testing Hot Reload

While the app is running, edit config.json:

{
  "app_name": "MyAwesomeApp",
  "debug": false,
  "port": 9000,
  "message": "Configuration updated without restart!"
}

Save the file, and you'll immediately see:

πŸ”„ Config file changed!

βœ… Configuration loaded: {AppName:MyAwesomeApp Debug:false Port:9000 Message:Configuration updated without restart!}

πŸ“Š MyAwesomeApp running on port 9000 (debug=false): Configuration updated without restart!

Technical Details

FileWatchSource

Uses fsnotify library for efficient, event-driven file watching:

  • Linux: Uses inotify
  • Windows: Uses ReadDirectoryChangesW
  • macOS/BSD: Uses kqueue
Thread-Safe Configuration

Configuration updates use sync.RWMutex:

  • Write lock during reload (exclusive)
  • Read lock during access (shared)
  • Ensures atomic configuration swaps

Comparison: FileWatch vs SIGHUP

Aspect FileWatch SIGHUP
Cross-platform βœ… Works everywhere ❌ Unix-only
Trigger Automatic (file save) Manual (kill -SIGHUP PID)
DX Edit & save β†’ reload Find PID β†’ terminal command
Kubernetes βœ… ConfigMap mounts ❌ Doesn't integrate

Verdict: FileWatch is superior for configuration hot reload.

  • control: Webhook-triggered reload (HTTP POST /reload)
  • supervisor: Worker restart patterns

Note: For production use, consider adding:

  • Configuration validation before applying
  • Rollback on invalid config
  • Audit logging of config changes

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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