Versions in this module Expand all Collapse all v0 v0.0.2 Nov 18, 2022 v0.0.1 Nov 17, 2022 Changes in this version + var ErrLimitExhausted = errors.New("requests limit exhausted") + var ErrRaceCondition = errors.New("race condition detected") + type Clock interface + Now func() time.Time + type ConcurrentBuffer struct + func NewConcurrentBuffer(locker DistLocker, concurrentStateBackend ConcurrentBufferBackend, ...) *ConcurrentBuffer + func (c *ConcurrentBuffer) Done(ctx context.Context, key string) error + func (c *ConcurrentBuffer) Limit(ctx context.Context, key string) error + type ConcurrentBufferBackend interface + Add func(ctx context.Context, key string) (int64, error) + Remove func(ctx context.Context, key string) error + type ConcurrentBufferInMemory struct + func NewConcurrentBufferInMemory(registry *Registry, ttl time.Duration, clock Clock) *ConcurrentBufferInMemory + func (c *ConcurrentBufferInMemory) Add(ctx context.Context, key string) (int64, error) + func (c *ConcurrentBufferInMemory) Remove(ctx context.Context, key string) error + type ConcurrentBufferRedis struct + func NewConcurrentBufferRedis(cli *redis.Client, key string, ttl time.Duration, clock Clock) *ConcurrentBufferRedis + func (c *ConcurrentBufferRedis) Add(ctx context.Context, key string) (int64, error) + func (c *ConcurrentBufferRedis) Remove(ctx context.Context, key string) error + type DistLocker interface + Lock func(ctx context.Context) error + Unlock func() error + type FixedWindow struct + func NewFixedWindow(capacity int64, rate time.Duration, ...) *FixedWindow + func (f *FixedWindow) Limit(ctx context.Context) (time.Duration, error) + type FixedWindowInMemory struct + func NewFixedWindowInMemory() *FixedWindowInMemory + func (f *FixedWindowInMemory) Increment(ctx context.Context, window time.Time, _ time.Duration) (int64, error) + type FixedWindowIncrementer interface + Increment func(ctx context.Context, window time.Time, ttl time.Duration) (int64, error) + type FixedWindowRedis struct + func NewFixedWindowRedis(cli *redis.Client, prefix string) *FixedWindowRedis + func (f *FixedWindowRedis) Increment(ctx context.Context, window time.Time, ttl time.Duration) (int64, error) + type LeakyBucket struct + func NewLeakyBucket(capacity int64, rate time.Duration, locker DistLocker, ...) *LeakyBucket + func (t *LeakyBucket) Limit(ctx context.Context) (time.Duration, error) + type LeakyBucketEtcd struct + func NewLeakyBucketEtcd(cli *clientv3.Client, prefix string, ttl time.Duration, raceCheck bool) *LeakyBucketEtcd + func (l *LeakyBucketEtcd) SetState(ctx context.Context, state LeakyBucketState) error + func (l *LeakyBucketEtcd) State(ctx context.Context) (LeakyBucketState, error) + type LeakyBucketInMemory struct + func NewLeakyBucketInMemory() *LeakyBucketInMemory + func (l *LeakyBucketInMemory) SetState(ctx context.Context, state LeakyBucketState) error + func (l *LeakyBucketInMemory) State(ctx context.Context) (LeakyBucketState, error) + type LeakyBucketRedis struct + func NewLeakyBucketRedis(cli *redis.Client, prefix string, ttl time.Duration, raceCheck bool) *LeakyBucketRedis + func (t *LeakyBucketRedis) SetState(ctx context.Context, state LeakyBucketState) error + func (t *LeakyBucketRedis) State(ctx context.Context) (LeakyBucketState, error) + type LeakyBucketState struct + Last int64 + func (s LeakyBucketState) IzZero() bool + type LeakyBucketStateBackend interface + SetState func(ctx context.Context, state LeakyBucketState) error + State func(ctx context.Context) (LeakyBucketState, error) + type LockConsul struct + func NewLockConsul(lock *api.Lock) *LockConsul + func (l *LockConsul) Lock(ctx context.Context) error + func (l *LockConsul) Unlock() error + type LockEtcd struct + func NewLockEtcd(cli *clientv3.Client, prefix string, logger Logger) *LockEtcd + func (l *LockEtcd) Lock(ctx context.Context) error + func (l *LockEtcd) Unlock() error + type LockNoop struct + func NewLockNoop() *LockNoop + func (n LockNoop) Lock(ctx context.Context) error + func (n LockNoop) Unlock() error + type LockZookeeper struct + func NewLockZookeeper(lock *zk.Lock) *LockZookeeper + func (l *LockZookeeper) Lock(_ context.Context) error + func (l *LockZookeeper) Unlock() error + type Logger interface + Log func(v ...interface{}) + type Registry struct + func NewRegistry() *Registry + func (r *Registry) Delete(key string) + func (r *Registry) DeleteExpired(now time.Time) int + func (r *Registry) Exists(key string) bool + func (r *Registry) GetOrCreate(key string, value func() interface{}, ttl time.Duration, now time.Time) interface{} + func (r *Registry) Len() int + type SlidingWindow struct + func NewSlidingWindow(capacity int64, rate time.Duration, ...) *SlidingWindow + func (s *SlidingWindow) Limit(ctx context.Context) (time.Duration, error) + type SlidingWindowInMemory struct + func NewSlidingWindowInMemory() *SlidingWindowInMemory + func (s *SlidingWindowInMemory) Increment(ctx context.Context, prev, curr time.Time, _ time.Duration) (int64, int64, error) + type SlidingWindowIncrementer interface + Increment func(ctx context.Context, prev, curr time.Time, ttl time.Duration) (prevCount, currCount int64, err error) + type SlidingWindowRedis struct + func NewSlidingWindowRedis(cli *redis.Client, prefix string) *SlidingWindowRedis + func (s *SlidingWindowRedis) Increment(ctx context.Context, prev, curr time.Time, ttl time.Duration) (int64, int64, error) + type StdLogger struct + func NewStdLogger() *StdLogger + func (l *StdLogger) Log(v ...interface{}) + type SystemClock struct + func NewSystemClock() *SystemClock + func (c *SystemClock) Now() time.Time + func (c *SystemClock) Sleep(d time.Duration) + type TokenBucket struct + func NewTokenBucket(capacity int64, refillRate time.Duration, locker DistLocker, ...) *TokenBucket + func (t *TokenBucket) Limit(ctx context.Context) (time.Duration, error) + func (t *TokenBucket) Take(ctx context.Context, tokens int64) (time.Duration, error) + type TokenBucketEtcd struct + func NewTokenBucketEtcd(cli *clientv3.Client, prefix string, ttl time.Duration, raceCheck bool) *TokenBucketEtcd + func (t *TokenBucketEtcd) SetState(ctx context.Context, state TokenBucketState) error + func (t *TokenBucketEtcd) State(ctx context.Context) (TokenBucketState, error) + type TokenBucketInMemory struct + func NewTokenBucketInMemory() *TokenBucketInMemory + func (t *TokenBucketInMemory) SetState(ctx context.Context, state TokenBucketState) error + func (t *TokenBucketInMemory) State(ctx context.Context) (TokenBucketState, error) + type TokenBucketRedis struct + func NewTokenBucketRedis(cli *redis.Client, prefix string, ttl time.Duration, raceCheck bool) *TokenBucketRedis + func (t *TokenBucketRedis) SetState(ctx context.Context, state TokenBucketState) error + func (t *TokenBucketRedis) State(ctx context.Context) (TokenBucketState, error) + type TokenBucketState struct + Available int64 + Last int64 + type TokenBucketStateBackend interface + SetState func(ctx context.Context, state TokenBucketState) error + State func(ctx context.Context) (TokenBucketState, error)