Documentation ¶
Overview ¶
krakendrate contains a collection of curated rate limit adaptors for the KrakenD framework
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func PseudoFNV64a ¶
Types ¶
type Backend ¶
type Backend interface { Load(string, func() interface{}) interface{} Store(string, interface{}) error }
Backend is the interface of the persistence layer
type Limiter ¶
type Limiter interface {
Allow() bool
}
Limiter defines a simple interface for a rate limiter
type LimiterStore ¶
LimiterStore defines the interface for a limiter lookup function
func NewLimiterStore ¶
func NewLimiterStore(maxRate float64, capacity int, backend Backend, logger logging.Logger) LimiterStore
NewLimiterStore returns a LimiterStore using the received backend for persistence
func NewMemoryStore ¶
func NewMemoryStore(maxRate float64, capacity int, logger logging.Logger) LimiterStore
NewMemoryStore returns a LimiterStore using the memory backend
type MemoryBackend ¶
type MemoryBackend struct {
// contains filtered or unexported fields
}
MemoryBackend implements the backend interface by wrapping a sync.Map
func NewMemoryBackend ¶
func NewMemoryBackend(ctx context.Context, ttl time.Duration) *MemoryBackend
func (*MemoryBackend) Load ¶
func (m *MemoryBackend) Load(key string, f func() interface{}) interface{}
Load implements the Backend interface
func (*MemoryBackend) Store ¶
func (m *MemoryBackend) Store(key string, v interface{}) error
Store implements the Backend interface
type ShardedMemoryBackend ¶
type ShardedMemoryBackend struct {
// contains filtered or unexported fields
}
ShardedMemoryBackend is a memory backend shardering the data in order to avoid mutex contention
func DefaultShardedMemoryBackend ¶
func DefaultShardedMemoryBackend(ctx context.Context) *ShardedMemoryBackend
DefaultShardedMemoryBackend is a 2018 sharded ShardedMemoryBackend
func NewShardedMemoryBackend ¶
func NewShardedMemoryBackend(ctx context.Context, shards uint64, ttl time.Duration, h Hasher) *ShardedMemoryBackend
NewShardedMemoryBackend returns a ShardedMemoryBackend with 'shards' shards
func (*ShardedMemoryBackend) Load ¶
func (b *ShardedMemoryBackend) Load(key string, f func() interface{}) interface{}
Load implements the Backend interface
func (*ShardedMemoryBackend) Store ¶
func (b *ShardedMemoryBackend) Store(key string, v interface{}) error
Store implements the Backend interface
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
TokenBucket is an implementation of the token bucket pattern
func NewTokenBucket ¶
func NewTokenBucket(rate float64, capacity uint64) *TokenBucket
NewTokenBucket returns a token bucket with the given rate and capacity, using the default clock and an initial stock of cap
func NewTokenBucketWithClock ¶
func NewTokenBucketWithClock(rate float64, capacity uint64, c Clock) *TokenBucket
NewTokenBucketWithClock returns a token bucket with the given rate, capacity, and clock and an initial stock of capacity
func NewTokenBucketWithInitialStock ¶
func NewTokenBucketWithInitialStock(r float64, capacity, i uint64, c Clock) *TokenBucket
NewTokenBucketWithInitialStock returns a token bucket with the given rate, capacity, clock and initial stock
func (*TokenBucket) Allow ¶
func (t *TokenBucket) Allow() bool
Allow flags if the current request can be processed or not. It updates the internal state if the request can be processed