Documentation
¶
Overview ¶
Example: PostgreSQL provider.
Models the runtime config of a checkout service: log level, request timeout, a rate limit, a maintenance feature flag, a database connection struct, and a list of allowed CORS origins. The PostgreSQL provider fetches every key under "checkout/" with a single batched query per poll cycle. Struct and array values are stored as JSON in the value column.
Run it end to end:
docker compose up -d
# wait a few seconds for Postgres to accept connections, then seed:
docker compose exec -T postgres psql -U postgres -d configdb <<'SQL'
CREATE TABLE IF NOT EXISTS config (config_key VARCHAR(255) PRIMARY KEY, config_value TEXT);
INSERT INTO config VALUES
('checkout/log_level', 'info'),
('checkout/request_timeout', '30s'),
('checkout/rate_limit_rps', '100'),
('checkout/maintenance_mode', 'false'),
('checkout/database', '{"host":"db.internal","port":5432,"max_open_conns":20}'),
('checkout/allowed_origins', '["https://app.example.com"]')
ON CONFLICT (config_key) DO UPDATE SET config_value = EXCLUDED.config_value;
SQL
go run main.go
Then change a value and watch the app log the event:
docker compose exec -T postgres psql -U postgres -d configdb \ -c "UPDATE config SET config_value='500' WHERE config_key='checkout/rate_limit_rps'"
Click to show internal directories.
Click to hide internal directories.