You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
API Gateway written in Go. Built with clean architecture principles, it sits in front of multiple microservices and handles cross-cutting concerns uniformly.
# 1. Clone and install dependencies
git clone <repo>cd api-gateway
go mod tidy
# 2. Start Redis
docker run -d -p 6379:6379 redis:7.2-alpine
# 3. Copy and edit config
cp .env.example .env
# Edit configs/config.yaml to add your upstream services# 4. Run
make run
Run with Docker Compose (full stack)
# Starts: gateway, Redis, Prometheus, Grafana, Jaeger, echo backend
make docker-up
# View logs
make docker-logs
# Include in Authorization header
curl -H "Authorization: Bearer <token>" http://localhost:8080/api/v1/users/me
API Key
# Seed a key
redis-cli SET "apikey:my-key"'{"user_id":"u1","email":"u@e.com","roles":["developer"]}' EX 86400
# Use it
curl -H "X-API-Key: my-key" http://localhost:8080/api/v1/products
Observability
Prometheus Metrics
Metric
Type
Labels
gateway_requests_total
Counter
method, service, status
gateway_request_duration_seconds
Histogram
method, service
gateway_upstream_requests_total
Counter
service, backend, status
gateway_upstream_duration_seconds
Histogram
service
gateway_active_connections
Gauge
—
gateway_cache_operations_total
Counter
service, result (hit/miss)
gateway_rate_limit_total
Counter
service
gateway_circuit_breaker_state
Gauge
service (0=closed, 1=half-open, 2=open)
Distributed Tracing
Configure the OTLP endpoint to send traces to Jaeger, Tempo, or any OpenTelemetry-compatible backend.
make dev # hot reload with Air
make test# all tests with race detector
make test-unit # unit tests only
make coverage # HTML coverage report
make lint # golangci-lint
make fmt # gofmt + goimports
Seeding test data
make seed
# or
bash scripts/seed.sh localhost:6379
Load Balancing Strategies
Strategy
Description
Best For
round_robin
Cycles through backends equally
Homogeneous backends
least_connections
Always picks backend with fewest active connections