Documentation
¶
Index ¶
- func DefaultKeyFunc(r *http.Request) string
- func FeatureGuard(featureKey string, next http.Handler) http.Handler
- func FeatureGuardFunc(featureKey string, next func(http.ResponseWriter, *http.Request)) http.Handler
- func RequireFeature(featureKeys ...string) func(http.Handler) http.Handler
- func RequireTier(minimumTier core.Tier, next http.Handler) http.Handler
- func TierBasedResponse(next http.Handler) http.Handler
- type CombinedLimiter
- type ConnectionLimiter
- type RateLimitConfig
- type RateLimitStatusHandler
- type RateLimiter
- type TierConnectionLimiter
- type TierRateLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultKeyFunc ¶
DefaultKeyFunc generates a rate limit key from the request
func FeatureGuard ¶
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 ¶
RequireFeature checks if a specific feature is available
func RequireTier ¶
RequireTier ensures the request comes from an account with minimum tier
Types ¶
type CombinedLimiter ¶
type CombinedLimiter struct {
// contains filtered or unexported fields
}
CombinedLimiter combines rate limiting and connection limiting
func NewCombinedLimiter ¶
func NewCombinedLimiter(tier core.Tier) *CombinedLimiter
NewCombinedLimiter creates a new combined limiter
func (*CombinedLimiter) GetTier ¶
func (cl *CombinedLimiter) GetTier() core.Tier
GetTier returns the current tier
func (*CombinedLimiter) Middleware ¶
func (cl *CombinedLimiter) Middleware(next http.Handler) http.Handler
Middleware returns the combined limiting middleware Apply connection limit first, then rate limit
func (*CombinedLimiter) UpdateTier ¶
func (cl *CombinedLimiter) UpdateTier(tier core.Tier)
UpdateTier updates both limiters to use new tier limits
type ConnectionLimiter ¶
type ConnectionLimiter struct {
// contains filtered or unexported fields
}
ConnectionLimiter limits concurrent connections
func NewConnectionLimiter ¶
func NewConnectionLimiter(maxPerClient, globalMax int) *ConnectionLimiter
NewConnectionLimiter creates a new connection limiter
func (*ConnectionLimiter) Acquire ¶
func (cl *ConnectionLimiter) Acquire(r *http.Request) bool
Acquire attempts to acquire a connection slot Returns true if acquired, false if at limit
func (*ConnectionLimiter) GetStats ¶
func (cl *ConnectionLimiter) GetStats() (perClient map[string]int, global int)
GetStats returns current connection statistics
func (*ConnectionLimiter) Middleware ¶
func (cl *ConnectionLimiter) Middleware(next http.Handler) http.Handler
Middleware returns the connection limiting middleware
func (*ConnectionLimiter) Release ¶
func (cl *ConnectionLimiter) Release(r *http.Request)
Release releases a connection slot
type RateLimitConfig ¶
type RateLimitConfig struct {
// RequestsPerMinute - max requests allowed per minute
RequestsPerMinute int
// Burst - max burst requests allowed (above steady rate)
Burst int
// BlockDuration - how long to block after limit exceeded
BlockDuration time.Duration
// KeyFunc - function to generate unique key for rate limiting
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 RateLimitStatusHandler ¶
type RateLimitStatusHandler struct {
// contains filtered or unexported fields
}
RateLimitStatusHandler returns JSON status about rate limits
func NewRateLimitStatusHandler ¶
func NewRateLimitStatusHandler(limiter *CombinedLimiter) *RateLimitStatusHandler
NewRateLimitStatusHandler creates a new status handler
func (*RateLimitStatusHandler) ServeHTTP ¶
func (h *RateLimitStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP returns rate limit status as JSON
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(r *http.Request) bool
Allow checks if a request is allowed under rate limits Returns true if allowed, false if rate limited
func (*RateLimiter) GetRateLimitConfig ¶
func (rl *RateLimiter) GetRateLimitConfig() RateLimitConfig
GetRateLimitConfig returns the current configuration
func (*RateLimiter) Middleware ¶
func (rl *RateLimiter) Middleware(next http.Handler) http.Handler
Middleware returns an HTTP middleware for rate limiting
func (*RateLimiter) Stop ¶
func (rl *RateLimiter) Stop()
Stop stops the rate limiter cleanup goroutine
type TierConnectionLimiter ¶
type TierConnectionLimiter struct {
// contains filtered or unexported fields
}
TierConnectionLimiter creates a connection limiter based on tier
func NewTierConnectionLimiter ¶
func NewTierConnectionLimiter(tier core.Tier) *TierConnectionLimiter
NewTierConnectionLimiter creates a new tier-aware connection limiter
func (*TierConnectionLimiter) Middleware ¶
func (tcl *TierConnectionLimiter) Middleware(next http.Handler) http.Handler
Middleware returns the connection limiting middleware
func (*TierConnectionLimiter) UpdateTier ¶
func (tcl *TierConnectionLimiter) UpdateTier(tier core.Tier)
UpdateTier updates the connection limiter to use new tier limits
type TierRateLimiter ¶
type TierRateLimiter struct {
// contains filtered or unexported fields
}
TierRateLimiter creates a rate limiter based on the tier configuration
func NewTierRateLimiter ¶
func NewTierRateLimiter(tier core.Tier) *TierRateLimiter
NewTierRateLimiter creates a new tier-aware rate limiter
func (*TierRateLimiter) GetTier ¶
func (trl *TierRateLimiter) GetTier() core.Tier
GetTier returns the current tier
func (*TierRateLimiter) Middleware ¶
func (trl *TierRateLimiter) Middleware(next http.Handler) http.Handler
Middleware returns the rate limiting middleware
func (*TierRateLimiter) UpdateTier ¶
func (trl *TierRateLimiter) UpdateTier(tier core.Tier)
UpdateTier updates the rate limiter to use new tier limits