-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathkrakendrate.go
40 lines (31 loc) · 1.04 KB
/
krakendrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// krakendrate contains a collection of curated rate limit adaptors for the KrakenD framework
package krakendrate
import (
"context"
"errors"
"time"
)
var (
// ErrLimited is the error returned when the rate limit has been exceded
ErrLimited = errors.New("rate limit exceded")
// DataTTL is the default eviction time
DataTTL = 10 * time.Minute
// DefaultShards are the number of shards to create by default
DefaultShards uint64 = 2048
now = time.Now
)
// Limiter defines a simple interface for a rate limiter
type Limiter interface {
Allow() bool
}
// LimiterStore defines the interface for a limiter lookup function
type LimiterStore func(string) Limiter
// Backend is the interface of the persistence layer
type Backend interface {
Load(string, func() interface{}) interface{}
Store(string, interface{}) error
}
// DefaultShardedMemoryBackend is a 2048 sharded ShardedMemoryBackend
func DefaultShardedMemoryBackend(ctx context.Context) *ShardedMemoryBackend {
return NewShardedMemoryBackend(ctx, DefaultShards, DataTTL, PseudoFNV64a)
}