Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type RateLimiter ¶ added in v0.4.4
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter struct is a wrapper around the juju Bucket struct
func NewRateLimiter ¶ added in v0.4.4
func NewRateLimiter(reqPerSec int64) *RateLimiter
NewRateLimiter is a constructor function for RateLimiter. It creates a new RateLimiter that allows reqPerSec requests per second.
func (*RateLimiter) Limit ¶ added in v0.4.4
func (l *RateLimiter) Limit(_ context.Context) error
Limit checks if a request should be allowed based on the current state of the bucket. If no tokens are available (i.e., if TakeAvailable(1) returns 0), it means the rate limit has been hit, so it returns true. If a token is available, it returns false, meaning the request can proceed.
Click to show internal directories.
Click to hide internal directories.