rate

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: GPL-3.0 Imports: 3 Imported by: 37

Documentation

Overview

Package rate provides a rate limiter hooker, this package is based on golang.org/x/time/rate

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Limiter controls the frequency of handling events.

func NewLimiter

func NewLimiter(interval time.Duration, burst int) *Limiter

NewLimiter returns a new Limiter Pointer.

func (*Limiter) Acquire

func (lim *Limiter) Acquire() bool

Acquire ...

func (*Limiter) AcquireN

func (lim *Limiter) AcquireN(n int) bool

AcquireN ...

func (*Limiter) Tokens

func (lim *Limiter) Tokens() float64

Tokens returns the left token of limiter.

type LimiterManager

type LimiterManager[K comparable] struct {
	// contains filtered or unexported fields
}

LimiterManager ...

func NewManager

func NewManager[K comparable](interval time.Duration, burst int) *LimiterManager[K]

NewManager ..

func (*LimiterManager[K]) Load

func (l *LimiterManager[K]) Load(key K) *Limiter

Load ...

Jump to

Keyboard shortcuts

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