postgresql

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: 8 Imported by: 0

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'"

Jump to

Keyboard shortcuts

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