Add configuration management with Viper
- Implement pkg/config package with Viper integration - Support environment variables with DLC_ prefix - Add configurable server host, port, and shutdown timeout - Update server to use configuration values - Add config.example.yaml template file - Update AGENTS.md with configuration documentation - Maintain backward compatibility with default values Configuration options: - DLC_SERVER_HOST (default: 0.0.0.0) - DLC_SERVER_PORT (default: 8080) - DLC_SHUTDOWN_TIMEOUT (default: 30s)
This commit is contained in:
70
AGENTS.md
70
AGENTS.md
@@ -38,6 +38,14 @@ This file documents the AI agents, tools, and development workflow for the Dance
|
||||
- Server management guide
|
||||
- API endpoint documentation
|
||||
|
||||
### Phase 5: Configuration Management (Completed ✅)
|
||||
- Viper integration for configuration
|
||||
- Environment variable support with DLC_ prefix
|
||||
- Customizable server host/port
|
||||
- Configurable shutdown timeout
|
||||
- Configuration validation and logging
|
||||
- Example configuration file
|
||||
|
||||
## 🛠️ Tools & Technologies
|
||||
|
||||
| Component | Technology | Version |
|
||||
@@ -45,6 +53,7 @@ This file documents the AI agents, tools, and development workflow for the Dance
|
||||
| Language | Go | 1.26.1 |
|
||||
| Router | Chi | v5.2.5 |
|
||||
| Logging | Zerolog | v1.35.0 |
|
||||
| Configuration | Viper | v1.21.0 |
|
||||
| Testing | Standard Library | - |
|
||||
| Dependency Management | Go Modules | - |
|
||||
|
||||
@@ -58,6 +67,8 @@ DanceLessonsCoach/
|
||||
│ └── server/ # Web server
|
||||
│ └── main.go
|
||||
├── pkg/
|
||||
│ ├── config/ # Configuration management
|
||||
│ │ └── config.go # Viper-based config
|
||||
│ ├── greet/ # Core domain logic
|
||||
│ │ ├── api_v1.go # API handlers
|
||||
│ │ ├── greet.go # Service implementation
|
||||
@@ -66,6 +77,7 @@ DanceLessonsCoach/
|
||||
│ └── server.go
|
||||
├── go.mod # Dependencies
|
||||
├── go.sum # Dependency checksums
|
||||
├── config.example.yaml # Configuration template
|
||||
├── README.md # User documentation
|
||||
├── AGENTS.md # This file
|
||||
└── .gitignore # Ignore patterns
|
||||
@@ -98,6 +110,64 @@ Server running on :8080
|
||||
- 30-second shutdown timeout
|
||||
- Proper resource cleanup
|
||||
|
||||
### Configuration Management
|
||||
|
||||
The server supports flexible configuration through environment variables with the `DLC_` prefix:
|
||||
|
||||
**Available Configuration Options:**
|
||||
|
||||
| Option | Environment Variable | Default Value | Description |
|
||||
|--------|---------------------|---------------|-------------|
|
||||
| Host | `DLC_SERVER_HOST` | `0.0.0.0` | Server bind address |
|
||||
| Port | `DLC_SERVER_PORT` | `8080` | Server listening port |
|
||||
| Shutdown Timeout | `DLC_SHUTDOWN_TIMEOUT` | `30s` | Graceful shutdown timeout |
|
||||
|
||||
**Usage Examples:**
|
||||
|
||||
```bash
|
||||
# Custom port
|
||||
export DLC_SERVER_PORT=9090
|
||||
go run cmd/server/main.go &
|
||||
|
||||
# Custom host and port
|
||||
export DLC_SERVER_HOST="127.0.0.1"
|
||||
export DLC_SERVER_PORT=8081
|
||||
go run cmd/server/main.go &
|
||||
|
||||
# Custom shutdown timeout
|
||||
export DLC_SHUTDOWN_TIMEOUT=45s
|
||||
go run cmd/server/main.go &
|
||||
```
|
||||
|
||||
**Configuration File Support:**
|
||||
|
||||
A `config.example.yaml` file is provided as a template:
|
||||
|
||||
```yaml
|
||||
server:
|
||||
host: "0.0.0.0"
|
||||
port: 8080
|
||||
|
||||
shutdown:
|
||||
timeout: 30s
|
||||
```
|
||||
|
||||
**Configuration Loading:**
|
||||
- Environment variables take precedence over defaults
|
||||
- All configuration is validated on startup
|
||||
- Invalid configurations cause server startup failure
|
||||
- Configuration values are logged at startup
|
||||
|
||||
**Verification:**
|
||||
```bash
|
||||
# Test with custom configuration
|
||||
DLC_SERVER_PORT=9090 DLC_SERVER_HOST="127.0.0.1" go run cmd/server/main.go
|
||||
|
||||
# Verify it's running on the custom port
|
||||
curl http://127.0.0.1:9090/api/health
|
||||
# Expected: {"status":"healthy"}
|
||||
```
|
||||
|
||||
### Checking Server Status
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user