Documentation
¶
Overview ¶
Package ratelimiting provides a per-key rate limiter interface using the token bucket algorithm.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimiter ¶
RateLimiter limits the rate of operations per key.
func NewInMemoryRateLimiter ¶
func NewInMemoryRateLimiter(requestsPerSec float64, burstSize int) RateLimiter
NewInMemoryRateLimiter returns a RateLimiter that uses per-key limiters in memory.
Example ¶
package main
import (
"context"
"fmt"
"github.com/verygoodsoftwarenotvirus/platform/v4/ratelimiting"
)
func main() {
limiter := ratelimiting.NewInMemoryRateLimiter(10.0, 5)
allowed, err := limiter.Allow(context.Background(), "user-123")
if err != nil {
panic(err)
}
fmt.Println(allowed)
}
Output: true
Click to show internal directories.
Click to hide internal directories.