ratelimit

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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