ratelimit

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBBRServiceOverload = errors.New("service overload with bbr")
)
View Source
var ErrUnknownPeriodCode = errors.New("unknown period code")

Functions

This section is empty.

Types

type BBR

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

BBR Bottleneck Bandwidth and RTT

func NewBBR

func NewBBR(options ...BBROptionFn) *BBR

func (*BBR) Allow

func (b *BBR) Allow() (Promise, error)

type BBROptionFn

type BBROptionFn func(*bbrOption)

func WithBBRBucket

func WithBBRBucket(buckets int) BBROptionFn

func WithBBRCpuThreshold

func WithBBRCpuThreshold(threshold int64) BBROptionFn

func WithBBRWindow

func WithBBRWindow(window time.Duration) BBROptionFn

type Period

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

func NewPeriod

func NewPeriod(seconds, quota int, store *redis.Redis, options ...PeriodOption) *Period

func (*Period) Take

func (p *Period) Take(ctx context.Context, key string) (PeriodCode, error)

type PeriodCode

type PeriodCode int
const (
	PeriodUnknown PeriodCode = iota
	PeriodAllowed
	PeriodHitQuota
	PeriodOverQuota
)

type PeriodOption

type PeriodOption func(p *Period)

func WithPeriodAlign

func WithPeriodAlign() PeriodOption

func WithPeriodPrefix

func WithPeriodPrefix(prefix string) PeriodOption

type Promise

type Promise interface {
	MarkSuccess()
	MarkFail()
}

type Token

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

func NewToken

func NewToken(rate, capacity int, store *redis.Redis, key string) *Token

func (*Token) Allow

func (t *Token) Allow(ctx context.Context) bool

func (*Token) AllowN

func (t *Token) AllowN(ctx context.Context, now time.Time, n int) bool

Jump to

Keyboard shortcuts

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