api-gateway

module
v0.0.0-...-76bc61f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2025 License: Apache-2.0

README

API Gateway

coverage go-report Go Reference

This service acts as the entrypoint to all client traffic and handles request forwarding to individual microservices such as auth-service and dashboard-service. It also manages authentication, routing, and headers.

git clone https://github.com/dashboard-platform/api-gateway.git
cd api-gateway

Run Locally

Option 1: Run with Go (requires PostgreSQL running locally)
  1. Create a .env file.
  2. Run:
go run cmd/main.go

.env file example: (for details, see below)

PORT=:8080
AUTH_SERVICE_URL=http://auth-service:8080
DASHBOARD_SERVICE_URL=http://dashboard-service:8080
JWT_SECRET=supersecretkey
COOKIE_SECURE=false

Option 2: Run with Docker
docker build -t api-gateway .
docker run -p 8080:8080 --env-file .env api-gateway

This will start the api-gateway on port 8080.

Access healthcheck:

curl http://localhost:8080/healthcheck

Run Tests

To run the whole test suite, use:

cd api-gateway
go tests -v ./...

Environment Variables

Variable Description
PORT Port on which the service runs (:8080)
AUTH_SERVICE Address where auth-service is running
DASHBOARD_SERVICE Address where dashboard-service is running
JWT_SECRET Secret used for signing JWTs (secret)
COOKIE_SECURE Use secured cookies or not

Features

  • Centralized routing for all internal APIs
  • JWT validation middleware (from cookie or bearer token)
  • Forwarding to internal microservices:
    • /auth/*auth-service
    • /dashboard/*dashboard-service
  • Cookie handling and header normalization
  • Built-in support for CORS and secure HTTP headers

Endpoints

Method Path Auth Required Description
GET /healthcheck Basic service

Directories

Path Synopsis
internal
config
Package config provides functionality for loading and managing application configuration.
Package config provides functionality for loading and managing application configuration.
logger
Package logger provides utilities for initializing and managing application logging.
Package logger provides utilities for initializing and managing application logging.
middleware
Package middleware provides reusable middleware components for the application.
Package middleware provides reusable middleware components for the application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL