Stage 3 · Build
Production-Ready Services
Configuration
Load environment variables, config files, secrets, and defaults with Viper, envconfig, or clean structs.
Why Configuration Management
Hardcoded values break when you move from development to production. Configuration management separates values from code, letting you run the same binary in different environments with different settings.
Environment Variables
Config Files
Secrets Management
Secrets like database passwords and API keys should never be in config files or git. Use environment variables, secret managers (Vault, AWS SSM), or Kubernetes secrets.
Validation
12-Factor Config
- Store config in environment variables, not in code.
- Separate config from code — same binary, different environments.
- Use defaults for non-critical settings.
- Validate all config on startup.
- Never log secrets or config file paths in production.
- Use typed config structs, not string maps.
Create a .env.example file with all required variables and placeholder values. Developers copy it to .env and fill in local values. Never commit .env to git.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.