Gateway CLI is a lightweight API Gateway tool written in Go. It routes HTTP requests to backend services based on a YAML-defined configuration. It supports rate limiting, access control, and middleware injection, and is fully configurable via config.yaml and services_config.yaml.
🚧 Note: This project is under active development and may contain bugs. Contributions and suggestions are welcome!
- 🔀 Request routing to multiple backend services
- 📄 Configuration via YAML files
- 🚦 Built-in rate limiting
- 🧩 Middleware support (
/gateway/middleware) - 🛠 CLI utility to manage and start the gateway
config.yaml: Gateway configuration (env, port, service config path)services_config.yaml: List of backend services, endpoints, routes, API keys, and rules
env: env
http_server:
address: localhost:4001
services_config_path: config/services_config.yamlservices:
- name: user-service
baseUrl: http://localhost:5001
service_endpoint: /service1
routes:
- method: "GET"
endpoint: /users
- method: "GET"
endpoint: /users/{id}
- method: "POST"
endpoint: /users
rate_limits: 1
api_key: xyc
allowlist:
- "192.168.1.5"
enabled: true- Clone the repository:
git clone <repository-url> cd <repository-dir> - Build the binary:
go build -o gateway-cli
To make the tool globally accessible:
- Open
~/.bashrc (or ~/.zshrc if using Zsh):nano ~/.bashrc - Add the following line:
alias gateway-cli="$HOME/DIR WHERE THE BUILD IS PLACED/gateway-cli" - Refresh your shell configuration:
. ~/.bashrc
gatewat-cli help| Command | Description |
|---|---|
config |
Load services config from specified path |
help |
Display help info |
service |
Add/Remove/List services to/from the YAML config |
start |
Start the API gateway server |
status |
Check gateway server status |
stop |
Stop the gateway server |
gateway-cli start -d-d,--daemon: Run server in background-h,--help: Help for start
If a client sends a request to:
<gateway_base_url>/service1/users
The gateway will proxy it to:
http://localhost:5001/users
You can modify or extend the gateway functionality by adding middleware to /gateway/middleware. Examples include:
- Custom logging
- Authentication
- Caching
- Retry logic
- Project is in early development.
- YAML validation is minimal.
- Rate limiter is basic (single token per service, adjustable per your needs).
Here are some upcoming improvements and considerations for the project:
-
Service-Specific Middleware
Separate service proxies to allow applying different middleware stacks for each individual service -
Reviewing
api_keyField
Theapi_keyfield inservices_config.yamlis currently unused. Will evaluate its purpose; it may be removed or repurposed in future versions. -
Redis-Based Rate Limiter
Replace or enhance the current in-memory rate limiter with a distributed Redis-based implementation for scalability and resilience. -
IP whitelisting per service
Got feedback or improvements?
Feel free to submit a pull request or open an issue.