Sentinel is a lightweight, configuration-driven API gateway and reverse proxy built with Go. It is designed to be a simple, performant, and extensible solution for managing and securing backend services through a single entry point.
- Configuration-Driven: Define all routing, load balancing, and plugin behavior in a single YAML or JSON file.
- Multiple Load Balancing Strategies: Choose from various algorithms like
round-robin
,random
,least-connections
,ip-hash
, andweighted
to distribute traffic effectively. - Extensible Plugin Architecture: Enhance gateway functionality with custom logic. The configuration supports plugins for concerns like authentication and rate-limiting.
- Command-Line Interface: Manage the gateway with a clean and simple CLI, built using Cobra.
- Schema Generation: Automatically generate a JSON schema for your configuration file to enable validation and autocompletion in your editor.
Technology | Description |
---|---|
Go | The core programming language used for development. |
Cobra | A powerful library for creating modern CLI applications. |
Echo | A high-performance, minimalist Go web framework. |
Follow these instructions to get a copy of the project up and running on your local machine.
-
Clone the repository:
git clone https://github.com/struckchure/sentinel.git cd sentinel
-
Install dependencies:
go mod tidy
-
Build the application:
go build -o sentinel ./cmd
This will create a
sentinel
executable in the root directory.
Sentinel is operated via its command-line interface and configured using a YAML file.
Create a sentinel.yaml
file to define your gateway's behavior. The gateway routes requests based on URL patterns to a set of backend services, applying load balancing and plugins as configured.
Here is an example configuration from sentinel.yaml
:
# yaml-language-server: $schema=sentinel.schema.json
host: localhost
port: 3000
backends:
- load_balancer: round-robin
patterns:
- from: /todos
to: /todos
- from: /todos/*
to: /todos/$1
middlewares:
- name: rate-limiter
config:
limit: 10
burst: 0
expires: 30s
- name: auth-n
config:
alg: RS256
jwk_url: string
jwt_secret: string
propagate_claims:
- from: sub
to: X-User
services:
- url: http://localhost:8010
- url: http://localhost:8020
- url: http://localhost:8030
- load_balancer: random
methods: ["OPTIONS", "GET", "POST"]
patterns:
- from: /todos-v2
to: /todos
- from: /todos-v2/*
to: /todos/$1
services:
- url: http://localhost:8010
- url: http://localhost:8020
- url: http://localhost:8030
Start the gateway using the run
command, specifying your configuration file with the -c
flag.
./sentinel run
The gateway will now listen for requests on localhost:3000
and forward traffic matching the /todo/*
pattern to the backend services localhost:8010
, localhost:8020
, and localhost:8030
using a round-robin strategy.
Sentinel provides several commands to help with development and management.
-
Run the Gateway
./sentinel run [flags]
Flags:
-c
,--config
: Path to the sentinel config file (default:sentinel.yaml
).
-
Generate Config Schema Generate a JSON schema to validate your configuration files.
./sentinel schema [flags]
Flags:
-i
,--indentation
: Indentation size for the output (default:2
).-s
,--save
: Save the schema to a file instead of printing to stdout.-o
,--output
: The output file path (default:sentinel.schema.json
).
-
Check Version Print the current version, commit, and build date.
./sentinel version
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request