Add environment variable configuration (v1.3.1)
Implements minimal environment-based configuration for the example
application, enabling production deployments to customize session
timeouts, rate limits, and server port without code changes.
New Configuration Variables (4 total):
SESSION_TIMEOUT_DAYS:
- Session cookie lifetime in days (default: 30)
- Range: 1-365 days (warnings outside range)
- Converts to seconds for cookie MaxAge
- Example: SESSION_TIMEOUT_DAYS=7 for weekly sessions
RATE_LIMIT_AUTH:
- Auth endpoint rate limit as "requests/sec,burst"
- Default: "5,10" (5 req/s, burst 10)
- Applies to /login and /callback endpoints
- Example: RATE_LIMIT_AUTH=10,20 for higher limits
RATE_LIMIT_API:
- API endpoint rate limit as "requests/sec,burst"
- Default: "10,20" (10 req/s, burst 20)
- Applies to /post, /create-record, /delete-record, /get-record
- Example: RATE_LIMIT_API=50,100 for high traffic
SERVER_PORT:
- HTTP server port (default: 8181)
- Example: SERVER_PORT=8080 for standard HTTP
Helper Functions:
- getEnvInt() - Parse integer env vars with validation/defaults
- getRateLimitConfig() - Parse "req/sec,burst" format with validation
- validateConfig() - Range validation with warning logs
Configuration Validation:
- Invalid values: Falls back to defaults, logs clear warnings
- Unusual values: Applied but logs configuration warnings
- Format errors: Shows expected format in error message
- Validates ranges: SESSION_TIMEOUT_DAYS (1-365), rate limits (0.1-1000)
Documentation (README.md):
- Comprehensive environment variable reference
- 4 example configurations (dev, staging, production, high-traffic)
- Deployment examples (command line, Docker, Docker Compose, K8s)
- Rate limiting guidelines by scenario
- Session timeout security recommendations
- Configuration validation behavior explained
Testing:
- Default values: All env vars optional, sensible defaults
- Custom values: SESSION_TIMEOUT_DAYS=7, RATE_LIMIT_AUTH=10,20 verified
- Invalid values: Falls back to defaults (tested "abc", "invalid")
- Unusual values: Applies with warnings (tested 400 days, 5000 req/s)
- Server startup logs show all configured values
Scope Decision (Minimal):
- Only 4 most critical production configuration needs
- Excluded (kept hardcoded with good defaults):
- HTTP client timeout (30s is industry standard)
- Server read/write/idle timeouts (best practice values)
- Cookie security flags (auto-detected, should not override)
- Logging level (already auto-configured)
Files Modified:
- examples/web-demo/main.go - Added env parsing, validation (~70 lines)
- README.md - Added Environment Variables section (~185 lines)
- TODO.md - Removed Issue #18
- COMPLETED_ISSUES.md - Added Issue #18 with implementation details
- VERSION.md - Added v1.3.1 release notes
Impact:
- No Library Changes: Example application only
- 100% Backward Compatible: All env vars optional
- 12-Factor Compliant: Environment-based configuration
- Production-Ready: Per-environment tuning without code changes
- Container-Friendly: Works with Docker, K8s, orchestration
Resolves Issue #18: Environment Configuration
๐ค Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>