ratelimit

package
v0.5.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ratelimit provides token-bucket rate limiting for the switchAILocal proxy. It supports both a global system-wide limiter and per-API-key limiters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(cfg config.RateLimiterConfig) gin.HandlerFunc

Middleware returns a Gin middleware that enforces rate limits. It checks the global limit first (cheapest), then per-key limit. Rate-limited requests receive HTTP 429 with a Retry-After header.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter manages global and per-key rate limiting using token bucket algorithm. The global limiter protects the system from total overload. Per-key limiters prevent any single client from monopolizing resources.

func New

New creates a new rate limiter from the given configuration. Starts a background goroutine to evict stale per-key entries every 5 minutes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL