Skip to content

Configuration reference

The application is configured with environment variables. A .env file in the working directory is read at startup; variables set in the real environment take precedence. Invalid values are reported together and the process exits before serving traffic.

Application

Variable Default Description
APP_NAME go-rest-template Service name used in logs, token issuer and traces.
APP_ENV development Runtime environment. Production tightens defaults and refuses insecure settings. One of: development, production.
APP_SHUTDOWN_TIMEOUT 10s Maximum time to wait for in-flight requests on shutdown.

HTTP server

Variable Default Description
HTTP_HOST 0.0.0.0 Interface the API listens on.
HTTP_PORT 8080 Port the API listens on.
HTTP_READ_TIMEOUT 5s Maximum time to read a request, including the body.
HTTP_WRITE_TIMEOUT 10s Maximum time to write a response.
HTTP_IDLE_TIMEOUT 1m0s Maximum time to keep an idle keep-alive connection open.
HTTP_REQUEST_TIMEOUT 30s Deadline applied to the context of every request.
HTTP_TRUSTED_PROXIES 0 Number of reverse proxies in front of the API whose X-Forwarded-For entries are trusted. 0 uses the TCP peer address.
HTTP_MAX_BODY_BYTES 1048576 Maximum accepted request body size in bytes.
HTTP_CORS_ALLOWED_ORIGINS * Comma-separated origins allowed by CORS. Use explicit origins in production.

Admin server

Variable Default Description
ADMIN_HOST 0.0.0.0 Interface the admin server (metrics, profiling) listens on. Keep it off the public network.
ADMIN_PORT 9090 Port of the admin server. 0 disables it.
ADMIN_PPROF_ENABLED false Expose net/http/pprof under /debug/pprof on the admin server.

Authentication

Variable Default Description
AUTH_ALGORITHM HS256 Access token signing algorithm. EdDSA publishes the public key at /.well-known/jwks.json. One of: HS256, EdDSA.
AUTH_SECRET change-me-in-production HMAC signing key for HS256. At least 32 characters in production.
AUTH_PRIVATE_KEY_FILE — Path to a PEM-encoded PKCS#8 Ed25519 private key. Required for EdDSA.
AUTH_ISSUER go-rest-template Value of the iss claim. Defaults to APP_NAME.
AUTH_ACCESS_TOKEN_TTL 15m0s Lifetime of access tokens.
AUTH_REFRESH_TOKEN_TTL 720h0m0s Lifetime of refresh tokens.
AUTH_BCRYPT_COST 12 bcrypt work factor, between 10 and 16.
AUTH_REGISTRATION_ENABLED true Allow anonymous callers to create regular user accounts.

Database

Variable Default Description
DATABASE_DRIVER sqlite Database backend. One of: sqlite, postgres.
DATABASE_URL — PostgreSQL connection string. Required when DATABASE_DRIVER=postgres.
SQLITE_PATH data/app.db SQLite database file. Used when DATABASE_DRIVER=sqlite.
DATABASE_AUTO_MIGRATE true Apply pending migrations at startup.
DATABASE_MAX_OPEN_CONNS 20 Maximum open connections (PostgreSQL).
DATABASE_MAX_IDLE_CONNS 5 Maximum idle connections (PostgreSQL).
DATABASE_CONN_MAX_IDLE_TIME 5m0s Maximum time a connection may stay idle (PostgreSQL).
DATABASE_CONN_MAX_LIFETIME 1h0m0s Maximum time a connection may be reused (PostgreSQL).

Bootstrap

Variable Default Description
BOOTSTRAP_ADMIN_ENABLED false Create an administrator at startup when none exists.
BOOTSTRAP_ADMIN_USERNAME — Username of the bootstrap administrator.
BOOTSTRAP_ADMIN_FIRST_NAME — First name of the bootstrap administrator.
BOOTSTRAP_ADMIN_LAST_NAME — Last name of the bootstrap administrator.
BOOTSTRAP_ADMIN_PASSWORD — Password of the bootstrap administrator, at least 12 characters.

OpenAPI

Variable Default Description
OPENAPI_VALIDATE_REQUESTS true Reject requests that do not match the OpenAPI contract.
OPENAPI_VALIDATE_RESPONSES true Fail responses that do not match the contract. Buffers every response, so it defaults to true in development and false in production.
OPENAPI_DOCS_ENABLED true Serve the interactive API reference at /docs.

Rate limiting

Variable Default Description
RATE_LIMIT_ENABLED true Throttle requests per client IP.
RATE_LIMIT_REQUESTS 100 Requests allowed per client IP in each window.
RATE_LIMIT_WINDOW 1m0s Length of the rate limit window.
RATE_LIMIT_LOGIN_REQUESTS 10 Login and token refresh attempts allowed per client IP in each window.

Logging

Variable Default Description
LOG_LEVEL INFO Minimum level of emitted log records. One of: DEBUG, INFO, WARN, ERROR.
LOG_FORMAT auto Log encoding. auto selects text in development and json in production. One of: auto, text, json.

Metrics

Variable Default Description
METRICS_ENABLED true Expose Prometheus metrics at /metrics on the admin server.

Tracing

Variable Default Description
OTEL_ENABLED false Export OpenTelemetry traces over OTLP/HTTP. The endpoint is set with OTEL_EXPORTER_OTLP_ENDPOINT.
OTEL_SERVICE_NAME go-rest-template Service name reported in traces. Defaults to APP_NAME.