go-cloud-gateway is a lightweight, configuration-driven API gateway written in Go. It functions as a reverse proxy, routing HTTP requests to backend services based on configurable predicates and applying request/response transformations through a pluggable filter system.
- Configurable Routing: Define routes using predicates based on path, method, and host matching.
- Pluggable Filters: Apply request and response transformations through a modular filter pipeline.
- Flexible Configuration: Support for both YAML and JSON configuration formats with built-in validation.
- Extensible Architecture: Utilize factory patterns for dynamic creation of filters and predicates.
- Lightweight and Efficient: Designed for minimal overhead and high performance.
The gateway's architecture is modular, comprising three main subsystems:
- Configuration System: Loads and validates gateway configurations, including routes, filters, and global settings.
- Request Processing Pipeline: Processes incoming HTTP requests through a series of filters before forwarding them to the appropriate backend service.
- Filter and Predicate Ecosystem: Provides a framework for defining and applying filters and predicates to control request routing and transformation.
- Go 1.24+ installed on your system.
-
Clone the repository:
git clone https://github.com/drathveloper/go-cloud-gateway.git cd go-cloud-gateway -
Execute tests:
make test -
Execute tests with coverage:
make test-cover
make test-html
-
Execute lint:
make lint
The gateway can be configured using either YAML or JSON files. A basic YAML configuration example:
gateway:
routes:
- id: example-route
uri: http://localhost:8080
predicates:
- name: Path
args:
patterns:
- /api/v1/*
filters:
- name: AddRequestHeader
args:
name: X-Request-ID
value: uuid
global-filters:
- name: RequestResponseLogger
global-timeout: 30s- Routes: Define individual routes with associated predicates and filters.
- Global Filters: Filters applied to all incoming requests.
- Settings: Global settings such as timeouts and client configurations.
The gateway's architecture allows for easy extension:
- Custom Filters: Implement the
Filterinterface and register your filter using theFilterFactory. - Custom Predicates: Implement the
Predicateinterface and register your predicate using thePredicateFactory.
This design enables dynamic creation and application of filters and predicates based on configuration, promoting flexibility and testability.
Key external libraries are used:
github.com/go-playground/validator/v10: For configuration validation.github.com/stretchr/testify: For additional testing utilities.golang.org/x/net: For http2 networking package.gopkg.in/yaml.v3: For parsing YAML configuration files.
Contributions are welcome! Please fork the repository and submit a pull request with your enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.
For more detailed information, refer to the DeepWiki documentation.