[WIP] This project is under active development.
A configurable HTTP reverse proxy and API gateway built in Go.
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
- 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
- Configure your endpoints in
configs/bff.yml - Run the application:
go run cmd/gateway/main.go
The gateway is configured via a YAML file (configs/bff.yml). See the example configuration for reference.
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:
- corscmd/gateway/: Application entry point and bootstrappinginternal/config/: Configuration management and type definitionsinternal/middleware/: HTTP middleware components (CORS, logging, etc.)internal/proxy/: Reverse proxy logic and request modificationinternal/server/: HTTP server setup and route handlingpkg/utils/: Shared utility functionsconfigs/: Configuration files
- Separation of Concerns: Each package has a single responsibility
- Testability: Components can be unit tested independently
- Maintainability: Changes to one component don't affect others
- Standard Go Layout: Follows Go community conventions
- Scalability: Easy to add new features and middleware