Skip to content

asce4s/gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[WIP] This project is under active development.

API Gateway

A configurable HTTP reverse proxy and API gateway built in Go.

Project Structure

gateway/
├── cmd/
│   └── gateway/
│       └── main.go          # Application entry point
├── internal/
│   ├── config/
│   │   ├── config.go        # Configuration loading
│   │   └── types.go         # Configuration type definitions
│   ├── middleware/
│   │   ├── cors.go          # CORS middleware
│   │   └── logging.go       # Request logging middleware
│   ├── proxy/
│   │   ├── proxy.go         # Reverse proxy creation
│   │   └── director.go      # Request director/modifier
│   └── server/
│       ├── server.go        # HTTP server setup
│       ├── handler.go       # Request handlers
│       └── routes.go        # Route registration
├── pkg/
│   └── utils/
│       └── utils.go         # Shared utilities
├── configs/
│   └── bff.yml             # Configuration file
├── go.mod
├── go.sum
└── README.md

Features

  • Reverse Proxy: Forward requests to backend services
  • CORS Support: Configurable CORS policies
  • Request Modification: Add headers and query parameters
  • Path Rewriting: Modify request paths before forwarding
  • Policy Engine: Apply policies like CORS globally or per endpoint
  • Configurable: YAML-based configuration

Usage

  1. Configure your endpoints in configs/bff.yml
  2. Run the application:
    go run cmd/gateway/main.go

Configuration

The gateway is configured via a YAML file (configs/bff.yml). See the example configuration for reference.

Example Configuration

policyDefinitions:
  cors:
    origin: "*"
    methods: ["GET", "POST", "PUT", "DELETE"]
    credentials: true

global:
  policies:
    - cors

endpoints:
  - path: /api
    methods:
      - GET
      - POST
    target:
      url: https://jsonplaceholder.typicode.com
    request:
      headers:
        "X-Forwarded-Host": "gateway.example.com"
      query:
        "version": "v1"
    policies:
      - cors

Architecture

  • cmd/gateway/: Application entry point and bootstrapping
  • internal/config/: Configuration management and type definitions
  • internal/middleware/: HTTP middleware components (CORS, logging, etc.)
  • internal/proxy/: Reverse proxy logic and request modification
  • internal/server/: HTTP server setup and route handling
  • pkg/utils/: Shared utility functions
  • configs/: Configuration files

Benefits of This Structure

  1. Separation of Concerns: Each package has a single responsibility
  2. Testability: Components can be unit tested independently
  3. Maintainability: Changes to one component don't affect others
  4. Standard Go Layout: Follows Go community conventions
  5. Scalability: Easy to add new features and middleware

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages