TheDocumentation Index
Fetch the complete documentation index at: https://mnah05-boiler-go-21-79.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
config package provides centralized configuration management for Boiler-Go applications. It loads environment variables from .env files and system environment, validates them, and provides a singleton configuration instance.
Types
Config
The main configuration struct that holds all application settings.The port number on which the API server will listen
PostgreSQL connection string (e.g.,
postgres://user:pass@localhost:5432/dbname)Redis server address (e.g.,
localhost:6379)Redis authentication password
Redis database index (0-15)
Timeout for health check operations
Graceful shutdown timeout for API server
Graceful shutdown timeout for worker processes
Log output destination:
stdout, file, or bothPath to log file when LogOutput is
file or both. Defaults to logs/api.log for API and logs/worker.log for workerFunctions
Load
Initializes configuration from environment variables and validates all settings. This function fails fast if any configuration is invalid.Logger instance for configuration-related logging
*Config - Validated configuration instance
Behavior:
- Attempts to load
.envfile (optional) - Parses environment variables using struct tags
- Validates required fields and formats
- Exits the application on validation errors
- Returns singleton configuration instance
Usage
Basic usage
Example from API server
Environment variables
| Variable | Type | Default | Required | Description |
|---|---|---|---|---|
APP_PORT | string | 8080 | No | API server port |
DATABASE_URL | string | - | Yes | PostgreSQL connection string |
REDIS_ADDR | string | - | Yes | Redis server address |
REDIS_PASSWORD | string | - | No | Redis password |
REDIS_DB | int | 0 | No | Redis database index |
HEALTH_CHECK_TIMEOUT | duration | 2s | No | Health check timeout |
API_SHUTDOWN_TIMEOUT | duration | 10s | No | API shutdown timeout |
WORKER_SHUTDOWN_TIMEOUT | duration | 30s | No | Worker shutdown timeout |
LOG_OUTPUT | string | stdout | No | Log output destination |
LOG_FILE | string | - | No | Log file path |
Validation
TheLoad function performs comprehensive validation:
- Database URL: Must use
postgres://orpostgresql://scheme with valid host and database name - Port: Must be a number between 1 and 65535
- Redis DB: Must be between 0 and 15
- Timeouts: Must be positive durations
- Log Output: Must be
stdout,file, orboth