gateway:基于 YAPL 的轻量级 API 网关项目

可用于实现路径路由和负载均衡的 API 管理。该项目提供基于路径的路由、轮询负载均衡、访问日志记录及多后端支持,配置简单,支持自定义监听地址和路由规则。【此简介由AI生成】

Branch1Tags0
FilesLast commitLast update
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago

gateway

Simple API Gateway with path-based routing and load balancing.

Overview

gateway is a lightweight API gateway built in YAPL that provides:

  • Path-based routing
  • Round-robin load balancing
  • Access logging
  • Multiple backend support per route

Configuration

Create a gateway.yaml file:

# gateway configuration file
listen: "127.0.0.1:9090"
access_log: true

routes:
  - prefix: "/api"
    backends:
      - "http://127.0.0.1:8081"
  - prefix: "/"
    backends:
      - "http://127.0.0.1:8082"

Config Options

Option Type Description
listen string Address to listen on (host:port)
access_log bool Enable/disable HTTP access logging
routes array List of route definitions
prefix string URL path prefix to match
backends array Backend server URLs

Usage

# Start gateway with default config
gateway serve

# Start with custom listen address
gateway serve --listen=0.0.0.0:3000

# Start with custom config file
gateway serve --config=./my-gateway.yaml

# Generate default config
gateway config init

# Show current configuration
gateway config show

# Show configured routes
gateway routes

Commands

  • serve - Start the gateway server
  • config init - Generate default config file
  • config show - Print current configuration
  • routes - Show configured routes
  • help - Show help message

Features

Routing

  • Prefix-based matching
  • Longest prefix match priority

Load Balancing

  • Round-robin distribution across backends
  • Health-aware backend selection

Logging

  • HTTP request/response logging
  • Configurable enable/disable

License

MIT

Introduction

可用于实现路径路由和负载均衡的 API 管理。该项目提供基于路径的路由、轮询负载均衡、访问日志记录及多后端支持,配置简单,支持自定义监听地址和路由规则。【此简介由AI生成】

Customize your domain