Skip to content

Latest commit

 

History

History
114 lines (79 loc) · 3.44 KB

File metadata and controls

114 lines (79 loc) · 3.44 KB

Go API Gateway 🚀

High-performance, lightweight API Gateway written in Go, featuring routing, rate limiting, observability, and resilience mechanisms.

Go Version License


✨ Features

  • Performance: Built with chi for fast, lightweight HTTP routing.
  • Rate Limiting: Per-IP token-bucket rate limiting to prevent upstream overload.
  • Resilience: Integrated Retry and Circuit Breaker patterns for proxying.
  • Observability: Native Prometheus metrics and structured logging.
  • Security: Request ID propagation and panic recovery middleware.
  • Documentation: Built-in OpenAPI specification and Swagger UI.
  • Modern: Fully containerized with Docker and Docker Compose.

🛠 Tech Stack


🚀 Getting Started

Prerequisites

  • Go 1.25+ (for local development)
  • Docker & Docker Compose (for running the full stack)

Quick Start (Docker)

To launch the Gateway along with the Auth service, Prometheus, Grafana, and Swagger UI:

docker compose up --build

Local Development

  1. Install dependencies:

    go mod download
  2. Run the server:

    go run ./cmd/server

    Note: Ensure AUTH_SERVICE_URL is configured if testing proxying.


⚙️ Configuration

The Gateway is configured using environment variables.

Variable Description Default
APP_PORT Port for the gateway server 8080
APP_ENV Environment (local, docker) local
LOG_LEVEL Logging level (debug, info, warn, error) info
AUTH_SERVICE_URL Upstream Auth service URL http://localhost:8081
UPSTREAM_TIMEOUT_SECONDS Proxy request timeout 5
RATE_LIMIT_RPS Allowed requests per second per IP 10
RATE_LIMIT_BURST Burst capacity per IP 20

🛣 API Endpoints

Internal

  • GET /health: Health check endpoint.
  • GET /metrics: Prometheus metrics.
  • GET /api/v1/ping: Simple connectivity test.
  • GET /docs/*: Serves openapi.yaml.

Proxying (to Auth Service)

  • ANY /api/v1/auth/*: Routed to Auth Service.
  • ANY /api/v1/users/*: Routed to Auth Service.

🛡 Resilience & Rate Limiting

  • Rate Limiting: Rejects excessive traffic with 429 Too Many Requests and includes Retry-After header.
  • Retries: Automatically retries failed requests to upstream services.
  • Circuit Breaker: Monitors upstream health and "trips" if failures exceed thresholds, preventing cascading failures.

📊 Monitoring & Docs

Service URL Credentials
Gateway http://localhost:8080 -
Swagger UI http://localhost:8082 -
Prometheus http://localhost:9090 -
Grafana http://localhost:3000 admin / admin

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.