Documentation ¶
Index ¶
- type MockRateLimiter
- func (l MockRateLimiter) MaxQuota() float64
- func (l MockRateLimiter) Quota() float64
- func (l MockRateLimiter) QuotaPerSec() float64
- func (l MockRateLimiter) SetMaxQuota(q float64) error
- func (l *MockRateLimiter) SetQuota(q float64)
- func (l MockRateLimiter) SetQuotaPerSec(r float64) error
- func (l MockRateLimiter) Stop()
- func (l MockRateLimiter) Throttle(request float64) bool
- func (l *MockRateLimiter) Tick()
- type RateLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockRateLimiter ¶
type MockRateLimiter struct {
// contains filtered or unexported fields
}
A mock rate limiter for external unittesting. The bucket is fill via the Tick call.
func NewMockRateLimiter ¶
func NewMockRateLimiter() *MockRateLimiter
func (MockRateLimiter) MaxQuota ¶
func (l MockRateLimiter) MaxQuota() float64
This returns the leaky bucket's maximum capacity.
func (MockRateLimiter) Quota ¶
func (l MockRateLimiter) Quota() float64
This returns the current available quota.
func (MockRateLimiter) QuotaPerSec ¶
func (l MockRateLimiter) QuotaPerSec() float64
This returns the leaky bucket's fill rate.
func (MockRateLimiter) SetMaxQuota ¶
This sets the leaky bucket's maximum capacity. The value must be non-negative.
func (*MockRateLimiter) SetQuota ¶
func (l *MockRateLimiter) SetQuota(q float64)
func (MockRateLimiter) SetQuotaPerSec ¶
This sets the leaky bucket's fill rate. The value must be non-negative.
func (MockRateLimiter) Throttle ¶
This blocks until the request amount of resources is acquired. This returns false if the request can be satisfied immediately. Otherwise, this returns true.
NOTE: When maxQuota is zero, or when the rate limiter is stopped, this returns immediately.
func (*MockRateLimiter) Tick ¶
func (l *MockRateLimiter) Tick()
type RateLimiter ¶
type RateLimiter interface { // This returns the leaky bucket's maximum capacity. MaxQuota() float64 // This sets the leaky bucket's maximum capacity. The value must be // non-negative. SetMaxQuota(q float64) error // This returns the leaky bucket's fill rate. QuotaPerSec() float64 // This sets the leaky bucket's fill rate. The value must be non-negative. SetQuotaPerSec(r float64) error // This returns the current available quota. Quota() float64 // This blocks until the request amount of resources is acquired. This // returns false if the request can be satisfied immediately. Otherwise, this // returns true. // // NOTE: When maxQuota is zero, or when the rate limiter is stopped, // this returns immediately. Throttle(request float64) bool // Stop the rate limiter. Stop() }
Interface for a thread-safe leaky bucket rate limiter.
func NewRateLimiter ¶
func NewRateLimiter( maxQuota float64, quotaPerSec float64) ( RateLimiter, error)