middleware

package
v0.0.63 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRateLimiter

func DefaultRateLimiter() zinc.Middleware

DefaultRateLimiter returns a rate limiter with default settings

func IPRateLimiter

func IPRateLimiter(rate, capacity float64) zinc.Middleware

IPRateLimiter returns a rate limiter that limits by IP address

func RateLimiter

func RateLimiter(config ...RateLimiterConfig) zinc.Middleware

RateLimiter returns a rate limiter middleware

Types

type RateLimiterConfig

type RateLimiterConfig struct {
	// Rate is the token refill rate per second
	Rate float64
	// Capacity is the maximum number of tokens in the bucket
	Capacity float64
	// IPLookup is the function to extract IP address for per-IP rate limiting
	// If nil, the rate limiter applies globally
	IPLookup func(*zinc.Context) string
	// KeyGenerator is a custom function to generate keys for rate limiting
	// If nil and IPLookup is set, IP is used as key
	// If both nil, global rate limiting is used
	KeyGenerator func(*zinc.Context) string
	// StatusCode is the response code when rate limit is exceeded
	StatusCode int
	// LimitReachedHandler is called when rate limit is reached
	LimitReachedHandler zinc.RouteHandler
}

RateLimiterConfig contains configuration for the rate limiter middleware

type TokenBucket

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

TokenBucket represents a simple token bucket rate limiter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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