ratelimit

package
v0.0.0-...-1e52381 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2025 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultLimiter

func NewDefaultLimiter(reqPerSec float64, burst int) limiter.Limiter

Types

type GoRedisRate

type GoRedisRate struct {
	// contains filtered or unexported fields
}

func NewGoRedis

func NewGoRedis(rdb *redis.Client, rps float64, burst int) *GoRedisRate

func (*GoRedisRate) Allow

func (d *GoRedisRate) Allow(key string) (bool, error)

func (*GoRedisRate) AllowN

func (d *GoRedisRate) AllowN(key string, n int) (bool, error)

func (*GoRedisRate) ForceN

func (d *GoRedisRate) ForceN(key string, n int) (bool, error)

ForceN is not implemented for GoRedisRate

type Mutex

type Mutex struct {
	M map[string]limiter.Limiter
	R float64
	B int
	// contains filtered or unexported fields
}

func NewMutex

func NewMutex(constuctor NewLimiterFn, reqPerSec float64, burst int) *Mutex

func (*Mutex) Allow

func (d *Mutex) Allow(key string) (bool, error)

func (*Mutex) AllowN

func (d *Mutex) AllowN(key string, n int) (bool, error)

func (*Mutex) ForceN

func (d *Mutex) ForceN(key string, n int) (bool, error)

type NewLimiterFn

type NewLimiterFn = func(rate float64, burst int) limiter.Limiter

type RWMutex

type RWMutex struct {
	M map[string]limiter.Limiter
	R float64
	B int
	// contains filtered or unexported fields
}

func NewRWMutex

func NewRWMutex(constructor NewLimiterFn, reqPerSec float64, burst int) *RWMutex

func (*RWMutex) Allow

func (d *RWMutex) Allow(key string) (bool, error)

func (*RWMutex) AllowN

func (d *RWMutex) AllowN(key string, n int) (bool, error)

func (*RWMutex) ForceN

func (d *RWMutex) ForceN(key string, n int) (bool, error)

type Ratelimiter

type Ratelimiter interface {
	Allow(string) (bool, error)
	AllowN(string, int) (bool, error)
}

func NewDefaultRatelimiter

func NewDefaultRatelimiter(reqPerSec float64, burst int) Ratelimiter

type RedisDelayedSync

type RedisDelayedSync struct {
	// contains filtered or unexported fields
}

func (*RedisDelayedSync) Allow

func (r *RedisDelayedSync) Allow(key string) (bool, error)

func (*RedisDelayedSync) AllowN

func (r *RedisDelayedSync) AllowN(key string, n int) (bool, error)

type RedisDelayedSyncOption

type RedisDelayedSyncOption struct {
	// SyncInterval is the interval to sync the rate limit to the redis
	// Adjust this value to trade off between the performance and the accuracy of the rate limit
	SyncInterval time.Duration
	TokenPerSec  float64
	Burst        int
	RedisClient  *redis.Client
}

type SyncMapLoadOrStore

type SyncMapLoadOrStore struct {
	R float64
	B int
	// contains filtered or unexported fields
}

func NewSyncMapLoadOrStore

func NewSyncMapLoadOrStore(constructor NewLimiterFn, reqPerSec float64, burst int) *SyncMapLoadOrStore

func (*SyncMapLoadOrStore) Allow

func (d *SyncMapLoadOrStore) Allow(key string) (bool, error)

func (*SyncMapLoadOrStore) AllowN

func (d *SyncMapLoadOrStore) AllowN(key string, n int) (bool, error)

func (*SyncMapLoadOrStore) ForceN

func (d *SyncMapLoadOrStore) ForceN(key string, n int) (bool, error)

type SyncMapLoadThenLoadOrStore

type SyncMapLoadThenLoadOrStore struct {
	R float64
	B int
	// contains filtered or unexported fields
}

func NewSyncMapLoadThenLoadOrStore

func NewSyncMapLoadThenLoadOrStore(constructor NewLimiterFn, reqPerSec float64, burst int) *SyncMapLoadThenLoadOrStore

func (*SyncMapLoadThenLoadOrStore) Allow

func (d *SyncMapLoadThenLoadOrStore) Allow(key string) (bool, error)

func (*SyncMapLoadThenLoadOrStore) AllowN

func (d *SyncMapLoadThenLoadOrStore) AllowN(key string, n int) (bool, error)

func (*SyncMapLoadThenLoadOrStore) ForceN

func (d *SyncMapLoadThenLoadOrStore) ForceN(key string, n int) (bool, error)

type SyncMapLoadThenStore

type SyncMapLoadThenStore[L limiter.Limiter] struct {
	// contains filtered or unexported fields
}

func NewSyncMapLoadThenStore

func NewSyncMapLoadThenStore[L limiter.Limiter](constructor func(float64, int) L, rps float64, burst int) *SyncMapLoadThenStore[L]

func (*SyncMapLoadThenStore[l]) Allow

func (r *SyncMapLoadThenStore[l]) Allow(key string) (bool, error)

func (*SyncMapLoadThenStore[L]) AllowN

func (r *SyncMapLoadThenStore[L]) AllowN(key string, n int) (bool, error)

func (*SyncMapLoadThenStore[L]) GetLimiter

func (r *SyncMapLoadThenStore[L]) GetLimiter(key string) L

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL