Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
TokenBucket is a token bucket rate limiter used to limit the frequency of requests. Its working principle is: over a period of time, it generates a certain number of tokens. For each request, if the number of tokens is ≥1, the request is allowed; otherwise, it is rejected. This ensures that the request frequency does not exceed the specified rate over a period of time.
func NewTokenBucket ¶
func NewTokenBucket(rate float64, capacity int) *TokenBucket
func (*TokenBucket) Allow ¶
func (tb *TokenBucket) Allow() bool
Click to show internal directories.
Click to hide internal directories.