Appearance
Configuration Reference
The [dummy-responder] supports multiple configuration methods to give you maximum flexibility. This reference covers all available configuration options and how to use them.
Configuration Methods
The service supports four configuration methods with the following priority order (highest to lowest):
- Command-line flags 🚩 - Highest priority, overrides everything
- Environment variables 🌍 - Second priority, overrides config file and defaults
- Configuration file 📄 - Third priority, overrides built-in defaults
- Built-in defaults ⚙️ - Lowest priority, used when nothing else is specified
Quick Start
Generate Example Configuration
bash
# Generate a config.yml with all options documented
./dummy-responder -gen-config
# Use custom filename
./dummy-responder -gen-config -config my-config.yml
Basic Usage Examples
bash
# Use defaults (port 8080)
./dummy-responder
# Use config file
./dummy-responder -config config.yml
# Override port via CLI (highest priority)
./dummy-responder -port 9090
# Override port via environment variable
PORT=3000 ./dummy-responder
# CLI overrides config file and environment
PORT=3000 ./dummy-responder -config config.yml -port 8080 # Uses port 8080
Command-Line Flags
Flag | Type | Description | Example |
---|---|---|---|
-port | string | Port to listen on | -port 8080 |
-config | string | Path to configuration file | -config /path/to/config.yml |
-gen-config | bool | Generate example configuration file | -gen-config |
-help | bool | Show help message | -help |
CLI Examples
bash
# Show all available options
./dummy-responder -help
# Use specific port
./dummy-responder -port 9090
# Use custom config file
./dummy-responder -config /etc/dummy-responder/config.yml
# Generate config and exit
./dummy-responder -gen-config
Environment Variables
Variable | Type | Default | Description |
---|---|---|---|
PORT | string | 8080 | Port to listen on |
HOST | string | 0.0.0.0 | Host/interface to bind to |
LOG_LEVEL | string | INFO | Log level (DEBUG, INFO, WARN, ERROR) |
MAX_CONNECTIONS | int | 1000 | Maximum concurrent connections |
Environment Variable Examples
bash
# Basic port override
PORT=9090 ./dummy-responder
# Multiple environment variables
PORT=8080 HOST=127.0.0.1 LOG_LEVEL=DEBUG ./dummy-responder
# Using .env file (with docker-compose)
echo "PORT=8080" > .env
echo "LOG_LEVEL=DEBUG" >> .env
docker run --env-file .env dummy-responder
Configuration File (YAML)
The configuration file uses YAML format and supports comprehensive settings for all aspects of the service.
Complete Configuration Example
yaml
# [dummy-responder] Configuration File
# All options with their default values
server:
port: "8080" # Port to listen on
host: "0.0.0.0" # Host/interface to bind to
readTimeout: 30s # HTTP read timeout
writeTimeout: 30s # HTTP write timeout
maxConnections: 1000 # Maximum concurrent connections
enableProfiling: false # Enable pprof endpoints (/debug/pprof/)
defaults:
responseCode: 200 # Default HTTP status code
message: "Hello, World!" # Default response message
contentType: "text/plain" # Default content type
delay: "0s" # Default response delay
failureRate: 0.0 # Default failure rate (0.0-1.0)
failureCode: 500 # Default failure status code
websocket:
enabled: true # Enable WebSocket endpoints
messageDelay: "5s" # Delay between automatic messages
maxClients: 100 # Maximum WebSocket clients
pingInterval: "30s" # WebSocket ping interval
enableEcho: true # Enable message echoing
enableBroadcast: true # Enable message broadcasting
sse:
enabled: true # Enable Server-Sent Events endpoints
eventDelay: "3s" # Delay between SSE events
maxClients: 100 # Maximum SSE clients
keepAlive: "30s" # SSE keep-alive interval
enableEvents: true # Enable automatic events
logging:
level: "INFO" # Log level (DEBUG, INFO, WARN, ERROR)
format: "text" # Log format (text, json)
timestamp: true # Include timestamps in logs
requestLog: true # Log HTTP requests
colorOutput: true # Enable colored log output
Minimal Configuration Example
You don't need to specify all options. Here's a minimal config that only overrides what you need:
yaml
# Minimal configuration - only specify what you want to change
server:
port: "9090"
defaults:
responseCode: 201
message: "Custom Default Message"
logging:
level: "DEBUG"
Configuration Sections
Server Configuration
Controls the HTTP server behavior.
yaml
server:
port: "8080" # Which port to listen on
host: "0.0.0.0" # Which interface to bind to (0.0.0.0 = all)
readTimeout: 30s # How long to wait for request headers/body
writeTimeout: 30s # How long to wait when writing response
maxConnections: 1000 # Maximum concurrent connections
enableProfiling: false # Enable Go pprof endpoints for debugging
Common Settings:
host: "127.0.0.1"
- Only accept local connectionshost: "0.0.0.0"
- Accept connections from any IPreadTimeout: 10s
- Faster timeout for high-load scenariosmaxConnections: 5000
- Higher limit for load testing
Default Response Behavior
Sets the default behavior for HTTP responses when not overridden by query parameters.
yaml
defaults:
responseCode: 200 # Default HTTP status (200, 404, 500, etc.)
message: "Hello, World!" # Default response body text
contentType: "text/plain" # Default content type
delay: "0s" # Default response delay
failureRate: 0.0 # Probability of returning error (0.0-1.0)
failureCode: 500 # HTTP status to return on simulated failure
Common Settings:
responseCode: 404
- Default to "Not Found" for testing error handlingdelay: "100ms"
- Add realistic network latencyfailureRate: 0.1
- 10% failure rate for resilience testingcontentType: "application/json"
- Default to JSON responses
WebSocket Configuration
Controls WebSocket endpoint behavior.
yaml
websocket:
enabled: true # Enable/disable WebSocket endpoints
messageDelay: "5s" # How often to send automatic messages
maxClients: 100 # Maximum concurrent WebSocket connections
pingInterval: "30s" # How often to send ping frames
enableEcho: true # Echo received messages back to sender
enableBroadcast: true # Broadcast messages to all connected clients
Common Settings:
enabled: false
- Disable WebSocket if not neededmessageDelay: "1s"
- Faster updates for real-time testingmaxClients: 1000
- Higher limit for load testingenableEcho: false
- Disable echo for broadcast-only scenarios
Server-Sent Events (SSE) Configuration
Controls SSE endpoint behavior.
yaml
sse:
enabled: true # Enable/disable SSE endpoints
eventDelay: "3s" # How often to send events
maxClients: 100 # Maximum concurrent SSE connections
keepAlive: "30s" # Keep-alive interval
enableEvents: true # Send automatic events
Common Settings:
enabled: false
- Disable SSE if not neededeventDelay: "1s"
- Faster events for real-time testingmaxClients: 1000
- Higher limit for load testingenableEvents: false
- Only send events on demand
Logging Configuration
Controls logging behavior.
yaml
logging:
level: "INFO" # Log verbosity (DEBUG, INFO, WARN, ERROR)
format: "text" # Log format (text, json)
timestamp: true # Include timestamps
requestLog: true # Log all HTTP requests
colorOutput: true # Use colored output (disable for logs)
Common Settings:
level: "DEBUG"
- Verbose logging for developmentlevel: "ERROR"
- Minimal logging for productionformat: "json"
- Structured logs for log aggregationcolorOutput: false
- Disable colors for log files
Configuration Use Cases
Development Environment
yaml
server:
port: "8080"
defaults:
delay: "100ms" # Simulate network latency
logging:
level: "DEBUG" # Verbose logging
requestLog: true # Log all requests
Load Testing
yaml
server:
port: "8080"
maxConnections: 10000 # High connection limit
defaults:
delay: "50ms" # Minimal delay
failureRate: 0.05 # 5% failure rate
websocket:
maxClients: 5000 # High WebSocket limit
sse:
maxClients: 5000 # High SSE limit
logging:
level: "WARN" # Minimal logging
requestLog: false # Disable request logging
Production Simulation
yaml
server:
port: "8080"
host: "0.0.0.0"
defaults:
responseCode: 200
delay: "200ms" # Realistic response time
failureRate: 0.02 # 2% failure rate
logging:
level: "INFO"
format: "json" # Structured logging
colorOutput: false # No colors in logs
Error Simulation
yaml
defaults:
responseCode: 500 # Default to server error
failureRate: 0.3 # 30% failure rate
failureCode: 503 # Service unavailable
delay: "2s" # Slow responses
logging:
level: "DEBUG" # Detailed error logging
Configuration Validation
The service validates configuration on startup and will exit with an error if:
- Port is empty or invalid
- Max connections is zero or negative
- Failure rate is outside 0.0-1.0 range
- Timeout values are negative
- Invalid duration formats (use Go duration format:
1s
,500ms
,2m
)
Valid Duration Formats
yaml
# Valid duration examples
delay: "1s" # 1 second
delay: "500ms" # 500 milliseconds
delay: "2m" # 2 minutes
delay: "1h30m" # 1 hour 30 minutes
delay: "0s" # No delay
# Invalid formats (will cause errors)
delay: "1 second" # ❌ Spaces not allowed
delay: "500" # ❌ Must include unit
delay: "2 minutes" # ❌ Spelled out units not allowed
Viewing Current Configuration
Via HTTP Endpoint
bash
# Get current configuration as JSON
curl http://localhost:8080/config | jq .
# Check specific configuration section
curl http://localhost:8080/config | jq .server
curl http://localhost:8080/config | jq .defaults
curl http://localhost:8080/config | jq .websocket
Via Startup Logs
The service prints key configuration information on startup:
🤖 [dummy-responder] starting with configuration:
📡 Server: 0.0.0.0:8080
📝 Log level: INFO
🔗 Max connections: 1000
📄 Config file: config.yml
Configuration File Locations
The service looks for configuration files in this order:
- Specified via
-config
flag (highest priority) config.yml
in current directory (default)- Built-in defaults (fallback)
Common Locations
bash
# Current directory (default)
./dummy-responder -config config.yml
# System-wide configuration
./dummy-responder -config /etc/dummy-responder/config.yml
# User-specific configuration
./dummy-responder -config ~/.config/dummy-responder/config.yml
# Project-specific configuration
./dummy-responder -config ./configs/test-environment.yml
Docker Configuration
Using Environment Variables
dockerfile
# Dockerfile
FROM alpine:latest
COPY dummy-responder /usr/local/bin/
ENV PORT=8080
ENV LOG_LEVEL=INFO
CMD ["dummy-responder"]
bash
# Docker run with environment variables
docker run -p 8080:8080 \
-e PORT=8080 \
-e LOG_LEVEL=DEBUG \
-e MAX_CONNECTIONS=2000 \
dummy-responder
Using Config File Mount
bash
# Mount config file into container
docker run -p 8080:8080 \
-v $(pwd)/config.yml:/app/config.yml \
dummy-responder -config /app/config.yml
Docker Compose Example
yaml
version: '3.8'
services:
dummy-responder:
image: dummy-responder
ports:
- "8080:8080"
environment:
- PORT=8080
- LOG_LEVEL=INFO
- MAX_CONNECTIONS=1000
volumes:
- ./config.yml:/app/config.yml
command: ["-config", "/app/config.yml"]
Kubernetes Configuration
Using ConfigMap
yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: dummy-responder-config
data:
config.yml: |
server:
port: "8080"
maxConnections: 1000
defaults:
responseCode: 200
delay: "100ms"
logging:
level: "INFO"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dummy-responder
spec:
replicas: 3
template:
spec:
containers:
- name: dummy-responder
image: dummy-responder:latest
args: ["-config", "/etc/config/config.yml"]
ports:
- containerPort: 8080
volumeMounts:
- name: config
mountPath: /etc/config
env:
- name: LOG_LEVEL
value: "INFO"
volumes:
- name: config
configMap:
name: dummy-responder-config
Troubleshooting Configuration
Common Issues
1. Service won't start
bash
# Check configuration validity
./dummy-responder -config config.yml -help
# Validate YAML syntax
python -c "import yaml; yaml.safe_load(open('config.yml'))"
2. Port binding errors
bash
# Check if port is already in use
lsof -i :8080
# Use different port
./dummy-responder -port 8081
3. Configuration not loading
bash
# Verify file exists and is readable
ls -la config.yml
# Check file contents
cat config.yml
# Use absolute path
./dummy-responder -config /absolute/path/to/config.yml
4. Environment variables not working
bash
# Verify environment variables are set
env | grep -E "(PORT|LOG_LEVEL|HOST)"
# Test with explicit values
PORT=8080 LOG_LEVEL=DEBUG ./dummy-responder
Debug Configuration Loading
Enable debug logging to see configuration loading process:
bash
# Show configuration loading details
LOG_LEVEL=DEBUG ./dummy-responder
# Output will show:
# ✅ Configuration loaded from config.yml
# 🤖 [dummy-responder] starting with configuration:
# 📡 Server: 0.0.0.0:8080
# 📝 Log level: DEBUG
# 📄 Config file: config.yml
Next Steps
- Try different configurations - Experiment with various settings
- Test override priority - See how CLI flags override config files
- Check the
/config
endpoint - View live configuration via HTTP - Monitor logs - Observe how different log levels affect output
- Load test - Use high connection limits for stress testing
For more examples and advanced usage, see the User Guide and Developer Guide.