ratelimiter

package
v0.0.0-...-2935971 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// If false it will only set a new limit if the action is allowed to happen
	// If true then they will set the limit period regardless
	SetWhenLimited bool

	// the timer period before limits are clear
	Period time.Duration
}

Config for the ratelimiter

type Limiter

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

Limiter is a ratelimit management thingy

func New

func New(c Config) *Limiter

New returns a new limiter

func (*Limiter) Allowed

func (l *Limiter) Allowed(key string) bool

Allowed returns if an action is allowed to happen but does not set a new limit

func (*Limiter) Disallowed

func (l *Limiter) Disallowed(key string) bool

Disallowed is the inverse of Allowed

func (*Limiter) Do

func (l *Limiter) Do(key string) bool

Do returns if an action is allowed to happen at this moment, and sets a new limit

func (*Limiter) DoWait

func (l *Limiter) DoWait(key string)

DoWait waits until the next event can happen

func (*Limiter) Dont

func (l *Limiter) Dont(key string) bool

Dont is the inverse of Do

func (*Limiter) HowLong

func (l *Limiter) HowLong(key string) time.Duration

HowLong returns how long key has to wait before it can try again

func (*Limiter) Limit

func (l *Limiter) Limit(key string)

Limit sets a new limit on key

func (*Limiter) XDo

func (l *Limiter) XDo(key string, dur time.Duration) bool

XDo is like do except you give it a custom time

func (*Limiter) XDoWait

func (l *Limiter) XDoWait(key string, period time.Duration)

XDoWait is DoWait but with custom time

func (*Limiter) XDont

func (l *Limiter) XDont(key string, dur time.Duration) bool

XDont is the inverse of XDo

func (*Limiter) XLimit

func (l *Limiter) XLimit(key string, dur time.Duration)

XLimit sets a new limit on key with a custom duration

Jump to

Keyboard shortcuts

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