Documentation ¶
Overview ¶
Package reili provides a simple but general purpose http rate limiter http middleware. It uses the rate package and support limit and burst at second window. Visitor identifier is defined by the end user.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter is the basic struct of reili that NewRateLimiter returns. All field are not exported so it should be used only for variable initialization.
func NewRateLimiter ¶
func NewRateLimiter(rps float64, burstReq int, identifier VisitorIdentifier) *RateLimiter
NewRateLimiter instantiates a new RateLimiter object. rps: requests per second burstReq: burst requests identifier: a Visitor Identifier interface
type VisitorIdentifier ¶
VisitorIdentifier is an interface with a single function requirement. The function that requires is a IdentifyVisitor(r *http.Request) (string, error) which is used to identify a user by a string using the *http.Request It is used in every Limit call to identify the user.