GoGate is a lightweight API gateway built with Go standard library HTTP primitives. It routes requests by path prefix, forwards traffic with httputil.ReverseProxy, applies middleware, and exposes small admin endpoints for route and backend health inspection.
- YAML-driven route configuration
- Longest-prefix route matching
- HTTP reverse proxy forwarding
- Per-route JWT authentication
- In-memory IP rate limiting
- Per-route timeout control
- Periodic backend
/healthchecks - JSON access logs with method, path, client IP, status, duration, and route
- Admin APIs for routes and health
- Example backend service for local and Docker testing
- Docker and Makefile workflows
The gateway loads configs/gateway.yaml by default. Use -config <path> to load another file.
server:
port: 8080
auth:
enabled: true
jwt_secret: "gateway-secret"
rate_limit:
enabled: true
requests_per_minute: 60
routes:
- name: user-service
path_prefix: /api/users
target: http://localhost:9001
timeout_ms: 3000
auth_required: trueWhen multiple routes match a request, the longest path_prefix wins. Backends are checked at <target>/health; unhealthy routes return 503.
Start three example backends in separate terminals:
make backend-user
make backend-order
make backend-publicStart the gateway:
make runThe gateway listens on http://localhost:8080.
docker compose up --buildThis starts the gateway plus the three example backend services.
Public route:
curl http://localhost:8080/public/pingAdmin APIs:
curl http://localhost:8080/admin/routes
curl http://localhost:8080/admin/healthAuthenticated routes require an HS256 JWT signed with gateway-secret:
curl -H "Authorization: Bearer <token>" http://localhost:8080/api/users/profileUnauthenticated requests to /api/users or /api/orders return 401.
make testThis runs configuration parsing, route matching, JWT authentication, rate limiting, reverse proxy, and health monitor tests.