rate_limit

package module
v0.0.0-...-f89596c Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RATELIMITER_ClearEveryN = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Lim

type Lim interface {
	Allow(time.Time) bool
	AllowWithContext(context.Context, time.Time) bool
	Stop()
	Last() time.Time
}

func NewLimiter

func NewLimiter(interval time.Duration, b int) (lim Lim, err error)

type LimiterV1

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

rate limiter using a time array

func NewLimiterV1

func NewLimiterV1(interval time.Duration, b int, strong bool) (limiter *LimiterV1, err error)

func (*LimiterV1) Allow

func (limiter *LimiterV1) Allow(now time.Time) (ok bool)

func (*LimiterV1) AllowWithContext

func (limiter *LimiterV1) AllowWithContext(ctx context.Context, now time.Time) (ok bool)

func (*LimiterV1) Last

func (limiter *LimiterV1) Last() time.Time

func (*LimiterV1) New

func (limiter *LimiterV1) New(interval time.Duration, b int, strong bool) (*LimiterV1, error)

(intf) New(time.Duration, int, bool) (intf, error), as golang 1.17 doesn't support generics

func (*LimiterV1) Stop

func (limiter *LimiterV1) Stop()

type LimiterV2

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

rate limiter using buffered channel

func NewLimiterV2

func NewLimiterV2(interval time.Duration, b int) (limiter *LimiterV2, err error)

func (*LimiterV2) Allow

func (limiter *LimiterV2) Allow(now time.Time) (ok bool)

func (*LimiterV2) AllowWithContext

func (limiter *LimiterV2) AllowWithContext(ctx context.Context, now time.Time) (ok bool)

func (*LimiterV2) Last

func (limiter *LimiterV2) Last() time.Time

func (*LimiterV2) New

func (limiter *LimiterV2) New(interval time.Duration, b int) (*LimiterV2, error)

func (*LimiterV2) Stop

func (limiter *LimiterV2) Stop()

type LimiterV3

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

rate limiter using a time array

func NewLimiterV3

func NewLimiterV3(interval time.Duration, b int, strong bool) (limiter *LimiterV3, err error)

func (*LimiterV3) Allow

func (limiter *LimiterV3) Allow(now time.Time) (ok bool)

func (*LimiterV3) AllowWithContext

func (limiter *LimiterV3) AllowWithContext(ctx context.Context, now time.Time) (ok bool)

func (*LimiterV3) Last

func (limiter *LimiterV3) Last() time.Time

func (*LimiterV3) New

func (limiter *LimiterV3) New(interval time.Duration, b int, strong bool) (*LimiterV3, error)

(intf) New(time.Duration, int, bool) (intf, error), as golang 1.17 doesn't support generics

func (*LimiterV3) Stop

func (limiter *LimiterV3) Stop()

type NewLim

type NewLim = func(time.Duration, int) Lim

type RateLimiter

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

func NewRL

func NewRL(secs int64, b int, newLim NewLim) (rl *RateLimiter, err error)

func NewRateLimiter

func NewRateLimiter(secs int64, b int) (rl *RateLimiter, err error)

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) (ok bool)

func (*RateLimiter) AllowWithContext

func (rl *RateLimiter) AllowWithContext(ctx context.Context, key string) (ok bool)

func (*RateLimiter) GetLimiter

func (rl *RateLimiter) GetLimiter(key string) (lim Lim)

func (*RateLimiter) Metrics

func (rl *RateLimiter) Metrics() (time.Duration, int, int)

func (*RateLimiter) Stop

func (rl *RateLimiter) Stop()

Jump to

Keyboard shortcuts

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