Documentation
¶
Index ¶
- func APIKeyExtractor(r *http.Request) string
- func FromContext(ctx context.Context) (*ratelimit.Result, bool)
- func PerEndpointKeyGenerator(userIDExtractor func(*http.Request) string) func(*http.Request) string
- func PerUserKeyGenerator(userIDExtractor func(*http.Request) string) func(*http.Request) string
- func WithContext(ctx context.Context, result *ratelimit.Result) context.Context
- type RateLimiterConfig
- type RateLimiterMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIKeyExtractor ¶
APIKeyExtractor extracts API key from request
func FromContext ¶
FromContext retrieves rate limit result from context
func PerEndpointKeyGenerator ¶
PerEndpointKeyGenerator generates a rate limit key per endpoint
func PerUserKeyGenerator ¶
PerUserKeyGenerator generates a rate limit key per user
Types ¶
type RateLimiterConfig ¶
type RateLimiterConfig struct {
// PerUser enables per-user rate limiting
PerUser bool
// PerEndpoint enables per-endpoint rate limiting
PerEndpoint bool
// UserIDExtractor extracts user ID from request
UserIDExtractor func(*http.Request) string
// IPExtractor extracts IP address from request
IPExtractor func(*http.Request) string
// KeyGenerator generates a rate limit key from request
KeyGenerator func(*http.Request) string
// OnRateLimitExceeded is called when rate limit is exceeded
OnRateLimitExceeded func(http.ResponseWriter, *http.Request, *ratelimit.Result)
// SkipPaths defines paths that should skip rate limiting
SkipPaths []string
// EndpointLimits defines custom limits for specific endpoints
EndpointLimits map[string]int
}
RateLimiterConfig contains middleware configuration
type RateLimiterMiddleware ¶
type RateLimiterMiddleware struct {
// contains filtered or unexported fields
}
RateLimiterMiddleware provides HTTP rate limiting middleware
func NewRateLimiterMiddleware ¶
func NewRateLimiterMiddleware(limiter *ratelimit.Limiter, config RateLimiterConfig) *RateLimiterMiddleware
NewRateLimiterMiddleware creates a new rate limiter middleware
func (*RateLimiterMiddleware) GetMetrics ¶
func (m *RateLimiterMiddleware) GetMetrics() ratelimit.Stats
GetMetrics returns the current metrics
func (*RateLimiterMiddleware) Handler ¶
func (m *RateLimiterMiddleware) Handler(next http.Handler) http.Handler
Handler returns an HTTP middleware handler
func (*RateLimiterMiddleware) Middleware ¶
func (m *RateLimiterMiddleware) Middleware(next http.HandlerFunc) http.HandlerFunc
Middleware returns a middleware function that can wrap http.HandlerFunc
func (*RateLimiterMiddleware) ResetMetrics ¶
func (m *RateLimiterMiddleware) ResetMetrics()
ResetMetrics resets all metrics
Click to show internal directories.
Click to hide internal directories.