task_id: “1.11” title: “Managing Configuration Settings” status: “pending” priority: “high” estimated_effort: “medium” created: “2025-07-24” assigned_to: “pair” related_rfds: “RFD 004”
Task 1.11: Managing Configuration Settings
Summary
Implement configuration management for buylater.email using command-line flags, environment variables, and sensible defaults to make the application more flexible and production-ready.
Motivation
Following Let’s Go Chapter 3.1, we need to move away from hardcoded configuration values (like port 4000) to a flexible configuration system. This will allow easy deployment across different environments and better operational control.
Acceptance Criteria
- Add command-line flag support for server address/port configuration
- Implement environment variable fallbacks for configuration
- Create configuration struct to hold all application settings
- Add configuration for template directory paths
- Add configuration for static file directory paths
- Support debug/production mode configuration
- Provide sensible defaults for all configuration options
- Update application struct to use configuration
- Document all available configuration options
Technical Requirements
Configuration Structure
type config struct {
port int
env string
staticDir string
htmlDir string
}
Implementation Details
- Use Go’s
flagpackage for command-line arguments - Support environment variable overrides
- Implement configuration validation
- Update main.go to parse and use configuration
- Make template and static file paths configurable
- Add help text for all configuration options
Dependencies
- Task 1.10 completed (HTTP handler interface foundation)
Testing Strategy
Unit Tests
- Test configuration parsing with various inputs
- Verify default values are applied correctly
- Test environment variable precedence
Integration Tests
- Application starts with default configuration
- Command-line flags override defaults correctly
- Environment variables work as expected
Manual Testing
- Start server with default settings
- Test custom port:
go run ./cmd/web -port=8080 - Test environment variables:
PORT=3000 go run ./cmd/web - Verify help output:
go run ./cmd/web -help - Test different environment modes (development/production)
Definition of Done
- All acceptance criteria met
- All specified tests pass
- Code follows project conventions (go fmt, go vet)
- Configuration system is well-documented
- No hardcoded values remain in application
- Environment-specific behavior works correctly
- Human verification completed successfully
- Git commit created with proper message format
Implementation Notes
Approach
Replace hardcoded values with a flexible configuration system that supports multiple sources (flags, environment, defaults) with proper precedence.
Key Files to Modify
cmd/web/main.go- Add configuration parsing and usagecmd/web/handlers.go- Update to use configurable paths
Configuration Options
port: Server port (default: 4000)env: Environment mode (default: “development”)static-dir: Static files directory (default: “./ui/static”)html-dir: HTML templates directory (default: “./ui/html”)
Potential Risks
- Configuration parsing errors could prevent startup
- Path resolution issues in different environments
- Environment variable naming conflicts
Success Metrics
Flexible, configurable buylater.email application that can be easily deployed and managed across different environments with proper configuration management.
Related Tasks
- Blocks: Future deployment and environment-specific configurations
- Blocked by: Task 1.10 (needs application struct foundation)
- Related: Production deployment and operational management
Implementation Log
Implementation details will be recorded here during development.
Final Verification
Human Tester: [Name]
Date Completed: [YYYY-MM-DD]
Verification Result: [Pass/Fail]
Notes: [Any issues found or additional observations]