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
Click to show internal directories.
Click to hide internal directories.