Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FixedWindowRateLimiter ¶
type FixedWindowRateLimiter struct {
// contains filtered or unexported fields
}
FixedWindowRateLimiter is an implementation of RateLimiter interface with a fixed window algorithm
func NewFixedWindowRateLimiter ¶
func NewFixedWindowRateLimiter(limit int, duration time.Duration, repo repository.Repository, clock clock.Clock) *FixedWindowRateLimiter
NewFixedWindowRateLimiter returns an instance of fixed window rate limiter. It takes limit & duration. The rate is defined as limit/duration. Example:
limit := 1 duration := 5*time.Second // this gives us a rate of 1 request per 5 second window rateLimiter := NewFixedWindowRateLimiter(limit, duration, repo, clock)
type RateLimiter ¶
type RateLimiter interface {
// Allow increments the rate of the request for a given key and returns
// information about the result of the request.
Allow(ctx context.Context, key string) (*Result, error)
}
RateLimiter is the interface of a rate limit module
type Result ¶
type Result struct {
// Allowed is the number of requests that are allowed at time.Now().
// Zero value means that the request is not allowed i.e. has exceeded
// the rate limit threshold
Allowed int
// Limit is the limit that was used to get this result
Limit int
// Remaining indicates how many remaining request is allowed at time.Now
Remaining int
// RetryAfer indicates the duration that requester need to wait
// until the request will be allowed. If the request is allowed,
// a zero value will be returned
RetryAfter time.Duration
// ResetAfter indicates the duration that the requester need to wait
// until the time moves to the next rate limit window and hence resetting
// the count. You can also think of this as the time when Limit == Remaining.
ResetAfter time.Duration
}
Result embodies information about the current state of the rate limit
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
httpserver
command
|
|
|
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
Click to show internal directories.
Click to hide internal directories.