rate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FixedWindow

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

FixedWindow limits rate in a fixed window.

func (*FixedWindow) Expired

func (window *FixedWindow) Expired() bool

func (*FixedWindow) Limit

func (window *FixedWindow) Limit() error

func (*FixedWindow) LimitAt

func (window *FixedWindow) LimitAt(now time.Time, n int) error

func (*FixedWindow) LimitN

func (window *FixedWindow) LimitN(n int) error

type Limiter

type Limiter interface {
	Limit() error
	LimitN(n int) error
	LimitAt(now time.Time, n int) error

	// Expired indicates whether limiter not updated for a long time.
	// Generally, it is used for garbage collection.
	Expired() bool
}

func NewFixedWindow

func NewFixedWindow(interval time.Duration, max int) Limiter

func NewTokenBucket

func NewTokenBucket(qps int, burst int) Limiter

func NewTokenBucketRate

func NewTokenBucketRate(qps rate.Limit, burst int) Limiter

type TokenBucket

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

func (*TokenBucket) Expired

func (bucket *TokenBucket) Expired() bool

func (*TokenBucket) Limit

func (bucket *TokenBucket) Limit() error

func (*TokenBucket) LimitAt

func (bucket *TokenBucket) LimitAt(now time.Time, n int) error

func (*TokenBucket) LimitN

func (bucket *TokenBucket) LimitN(n int) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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