Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrRateLimitExceeded error = errors.New("rate limit exceeded")
Functions ¶
Types ¶
type Context ¶
type Context struct { StatusCode int Err error Limiter *limiter RequestLimit int WindowLen time.Duration RateLimitRemaining int RateLimitReset int Next http.Handler Key string // contains filtered or unexported fields }
Context is the error returned by the middleware.
type Limiter ¶
type Limiter interface { // Name returns the name of the limiter Name() string // Rule returns the key and rate limit rule for the request Rule(r *http.Request) (rule *Rule, err error) // ShouldSetXRateLimitHeaders returns true if the X-RateLimit-* headers should be set ShouldSetXRateLimitHeaders(*Context) bool // OnRequestLimit returns the handler to be called when the rate limit is exceeded OnRequestLimit(*Context) http.HandlerFunc }
type Rule ¶
type Rule struct { // Key for the rate limit Key string // ReqLimit is the request limit for the window // If ReqLimit is negative, the limiter is skipped ReqLimit int // WindowLen is the length of the window WindowLen time.Duration // IgnoreAfter is true if skip all limiters after this limiter IgnoreAfter bool }
Rule is a rate limit rule
Click to show internal directories.
Click to hide internal directories.