rate

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

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) LastTouch

func (lim *Limiter) LastTouch() int64

LastTouch ...

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]) Delete

func (l *LimiterManager[K]) Delete(key K)

Delete 删除对应限速器

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