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(metricsProvider metrics.Provider, requestsPerSec float64, burstSize int) (RateLimiter, error)
NewInMemoryRateLimiter returns a RateLimiter that uses per-key limiters in memory.
Example ¶
package main
import (
"context"
"fmt"
"github.com/primandproper/platform/ratelimiting"
)
func main() {
limiter, err := ratelimiting.NewInMemoryRateLimiter(nil, 10.0, 5)
if err != nil {
panic(err)
}
var allowed bool
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.