middleware

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultKeyFunc

func DefaultKeyFunc(r *http.Request) string

DefaultKeyFunc generates a rate limit key from the request

func FeatureGuard

func FeatureGuard(featureKey string, next http.Handler) http.Handler

FeatureGuard middleware checks if the current license tier allows access to a feature

func FeatureGuardFunc

func FeatureGuardFunc(featureKey string, next func(http.ResponseWriter, *http.Request)) http.Handler

FeatureGuardFunc is a convenience wrapper for http.HandlerFunc

func RequireFeature

func RequireFeature(featureKeys ...string) func(http.Handler) http.Handler

RequireFeature checks if a specific feature is available

func RequireTier

func RequireTier(minimumTier core.Tier, next http.Handler) http.Handler

RequireTier ensures the request comes from an account with minimum tier

func TierBasedResponse

func TierBasedResponse(next http.Handler) http.Handler

TierBasedResponse modifies the response based on tier

Types

type RateLimitConfig

type RateLimitConfig struct {
	RequestsPerMinute int
	Burst             int
	BlockDuration     time.Duration
	KeyFunc           func(r *http.Request) string
}

RateLimitConfig holds rate limiting configuration

func DefaultRateLimitConfig

func DefaultRateLimitConfig(tier core.Tier) RateLimitConfig

DefaultRateLimitConfig returns default configuration based on tier

type RateLimiter

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

RateLimiter implements per-client rate limiting using token bucket

func NewRateLimiter

func NewRateLimiter(config RateLimitConfig) *RateLimiter

NewRateLimiter creates a new rate limiter with the given configuration

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) (allow bool, remain int, retryIn time.Duration)

Allow checks if a request should be allowed and updates rate limits

func (*RateLimiter) Middleware

func (rl *RateLimiter) Middleware(next http.Handler) http.Handler

Middleware returns a middleware that applies rate limiting

Jump to

Keyboard shortcuts

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