file

command
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Example: File provider.

Models the runtime config of a checkout service in a local JSON file: log level, request timeout, a rate limit, a maintenance feature flag, a database connection struct, and a list of allowed CORS origins. The file provider watches the file with fsnotify and re-reads it on every change. Nested objects and arrays are decoded into struct and array config values.

Run it end to end:

docker compose up -d   # writes /tmp/checkout-config.json
go run main.go

Then edit the file and watch the app log the event:

cat > /tmp/checkout-config.json <<'JSON'
{
  "log_level": "debug",
  "request_timeout": "45s",
  "rate_limit_rps": 500,
  "maintenance_mode": true,
  "database": {"host": "db.prod", "port": 6543, "max_open_conns": 50},
  "allowed_origins": ["https://app.example.com", "https://admin.example.com"]
}
JSON

Jump to

Keyboard shortcuts

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