Skip to content

struckchure/sentinel

Repository files navigation

Sentinel API Gateway

Go Version Go Report Card

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.

✨ Key Features

  • 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, and weighted 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.

🛠️ Technologies Used

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.

🚀 Getting Started

Follow these instructions to get a copy of the project up and running on your local machine.

Installation

  1. Clone the repository:

    git clone https://github.com/struckchure/sentinel.git
    cd sentinel
  2. Install dependencies:

    go mod tidy
  3. Build the application:

    go build -o sentinel ./cmd

    This will create a sentinel executable in the root directory.

⚙️ Usage

Sentinel is operated via its command-line interface and configured using a YAML file.

1. Configuration

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

2. Running the Gateway

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.

3. CLI Commands

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

🤝 Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Dokugen

About

Simple and Lightweight API Gateway

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published