Documentation
¶
Overview ¶
internal/ratelimit/burst.go
internal/ratelimit/headers.go
internal/ratelimit/tenant_limits.go
Index ¶
- func FormatRateLimitError(w http.ResponseWriter, retryAfter int)
- func SetHeaders(w http.ResponseWriter, info RateLimitInfo, useIETF bool)
- type AdaptiveBurstLimiter
- type BurstLimiter
- type FixedWindowLimiter
- type HeaderLimiter
- type OperationConfig
- type OperationLimiter
- func (ol *OperationLimiter) Allow(tenantID, operation string) bool
- func (ol *OperationLimiter) GetLimit(operation string) (ratePerSecond, burst int, exists bool)
- func (ol *OperationLimiter) SetLimit(operation string, ratePerSecond, burst int)
- func (ol *OperationLimiter) Wait(ctx context.Context, tenantID, operation string) error
- type RateLimitInfo
- type RedisLimiter
- type SlidingWindowLimiter
- type TenantLimiter
- func (tl *TenantLimiter) Allow(tenantID, operation string) bool
- func (tl *TenantLimiter) GetTenantTier(tenantID string) (string, bool)
- func (tl *TenantLimiter) SetDefaultLimit(operation string, ratePerSecond, burst int)
- func (tl *TenantLimiter) SetTenantLimit(tenantID, operation string, ratePerSecond, burst int)
- func (tl *TenantLimiter) SetTenantTier(tenantID, tier string)
- func (tl *TenantLimiter) SetTierLimit(tier, operation string, ratePerSecond, burst int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatRateLimitError ¶
func FormatRateLimitError(w http.ResponseWriter, retryAfter int)
FormatRateLimitError formats a rate limit error response
func SetHeaders ¶
func SetHeaders(w http.ResponseWriter, info RateLimitInfo, useIETF bool)
SetHeaders adds rate limit headers to a response
Types ¶
type AdaptiveBurstLimiter ¶
type AdaptiveBurstLimiter struct {
// contains filtered or unexported fields
}
AdaptiveBurstLimiter adjusts burst based on behavior
func NewAdaptiveBurstLimiter ¶
func NewAdaptiveBurstLimiter(ratePerSecond, baseBurst, maxBurst int) *AdaptiveBurstLimiter
NewAdaptiveBurstLimiter creates an adaptive burst limiter
func (*AdaptiveBurstLimiter) Allow ¶
func (abl *AdaptiveBurstLimiter) Allow(tenantID string) bool
Allow checks if a tenant can proceed
func (*AdaptiveBurstLimiter) GetBurst ¶
func (abl *AdaptiveBurstLimiter) GetBurst(tenantID string) int
GetBurst returns current burst for a tenant
type BurstLimiter ¶
type BurstLimiter struct {
// contains filtered or unexported fields
}
BurstLimiter handles burst capacity with token bucket
func NewBurstLimiter ¶
func NewBurstLimiter(ratePerSecond, burst int) *BurstLimiter
NewBurstLimiter creates a limiter with burst handling
func (*BurstLimiter) Allow ¶
func (bl *BurstLimiter) Allow() bool
Allow checks if a request can proceed
type FixedWindowLimiter ¶
type FixedWindowLimiter struct {
// contains filtered or unexported fields
}
FixedWindowLimiter implements fixed window algorithm
func NewFixedWindowLimiter ¶
func NewFixedWindowLimiter(limit int, window time.Duration) *FixedWindowLimiter
NewFixedWindowLimiter creates a fixed window rate limiter
func (*FixedWindowLimiter) Allow ¶
func (f *FixedWindowLimiter) Allow(key string) bool
Allow checks if request can proceed
type HeaderLimiter ¶
type HeaderLimiter struct {
// contains filtered or unexported fields
}
HeaderLimiter adds rate limit headers to HTTP responses
func NewHeaderLimiter ¶
func NewHeaderLimiter(ratePerSecond, burst int) *HeaderLimiter
NewHeaderLimiter creates a new header-aware limiter
func (*HeaderLimiter) GetInfo ¶
func (hl *HeaderLimiter) GetInfo() RateLimitInfo
GetInfo returns current rate limit info
func (*HeaderLimiter) Middleware ¶
func (hl *HeaderLimiter) Middleware(next http.Handler) http.Handler
Middleware wraps an HTTP handler with rate limiting
func (*HeaderLimiter) UseIETFDraft ¶
func (hl *HeaderLimiter) UseIETFDraft(use bool)
UseIETFDraft enables IETF draft headers
type OperationConfig ¶
OperationConfig defines limits for an operation
type OperationLimiter ¶
type OperationLimiter struct {
// contains filtered or unexported fields
}
OperationLimiter manages rate limits per operation type
func NewOperationLimiter ¶
func NewOperationLimiter() *OperationLimiter
NewOperationLimiter creates a new operation-aware limiter
func (*OperationLimiter) Allow ¶
func (ol *OperationLimiter) Allow(tenantID, operation string) bool
Allow checks if a tenant can perform an operation
func (*OperationLimiter) GetLimit ¶
func (ol *OperationLimiter) GetLimit(operation string) (ratePerSecond, burst int, exists bool)
GetLimit returns the configured limit for an operation
func (*OperationLimiter) SetLimit ¶
func (ol *OperationLimiter) SetLimit(operation string, ratePerSecond, burst int)
SetLimit configures rate limit for an operation
type RateLimitInfo ¶
type RateLimitInfo struct {
Limit int `json:"limit"`
Remaining int `json:"remaining"`
Reset int64 `json:"reset"`
}
RateLimitInfo contains rate limit information
type RedisLimiter ¶
type RedisLimiter struct {
}
RedisLimiter for true distributed rate limiting (placeholder)
type SlidingWindowLimiter ¶
type SlidingWindowLimiter struct {
// contains filtered or unexported fields
}
SlidingWindowLimiter implements sliding window algorithm
func NewSlidingWindowLimiter ¶
func NewSlidingWindowLimiter(limit int, window time.Duration) *SlidingWindowLimiter
NewSlidingWindowLimiter creates a sliding window rate limiter
func (*SlidingWindowLimiter) Allow ¶
func (s *SlidingWindowLimiter) Allow(key string) bool
Allow checks if request can proceed
func (*SlidingWindowLimiter) Cleanup ¶
func (s *SlidingWindowLimiter) Cleanup()
Cleanup removes old entries (run periodically)
type TenantLimiter ¶
type TenantLimiter struct {
// contains filtered or unexported fields
}
TenantLimiter manages per-tenant rate limit customization
func NewTenantLimiter ¶
func NewTenantLimiter() *TenantLimiter
NewTenantLimiter creates a new tenant-aware limiter
func (*TenantLimiter) Allow ¶
func (tl *TenantLimiter) Allow(tenantID, operation string) bool
Allow checks if a tenant can perform an operation
func (*TenantLimiter) GetTenantTier ¶
func (tl *TenantLimiter) GetTenantTier(tenantID string) (string, bool)
GetTenantTier returns the tier for a tenant
func (*TenantLimiter) SetDefaultLimit ¶
func (tl *TenantLimiter) SetDefaultLimit(operation string, ratePerSecond, burst int)
SetDefaultLimit sets the default rate limit for an operation
func (*TenantLimiter) SetTenantLimit ¶
func (tl *TenantLimiter) SetTenantLimit(tenantID, operation string, ratePerSecond, burst int)
SetTenantLimit sets a custom limit for a specific tenant
func (*TenantLimiter) SetTenantTier ¶
func (tl *TenantLimiter) SetTenantTier(tenantID, tier string)
SetTenantTier assigns a tenant to a tier
func (*TenantLimiter) SetTierLimit ¶
func (tl *TenantLimiter) SetTierLimit(tier, operation string, ratePerSecond, burst int)
SetTierLimit sets limits for a tier