throttling

package
v1.6.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

func New

func New(options ...Option) (*Limiter, error)

func (*Limiter) Allow

func (l *Limiter) Allow(ctx context.Context, cost, rate, window int64, key string) (
	bool, func(context.Context) error, error,
)

Allow returns true if the limit is not exceeded, false otherwise.

type Option

type Option func(*Limiter)

Option is a functional option for the limiter, see With* functions for reference

func WithInMemoryGCRA

func WithInMemoryGCRA(burst int64) Option

WithInMemoryGCRA allows to use the GCRA algorithm (in-memory) with the specified burst or with the burst as rate if the provided burst is <= 0

func WithRedisGCRA

func WithRedisGCRA(rc *redis.Client, burst int64) Option

WithRedisGCRA allows to use the GCRA algorithm (Redis version) with the specified burst or with the burst as rate if the provided burst is <= 0

func WithRedisSortedSet

func WithRedisSortedSet(rc *redis.Client) Option

WithRedisSortedSet allows to use the Redis SortedSet algorithm for rate limiting

func WithStatsCollector

func WithStatsCollector(sc statsCollector) Option

WithStatsCollector allows to setup a stats collector for the limiter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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