rate

package
v1.3.90 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LimitLevel

type LimitLevel int
const (
	EnumLevelGlobal LimitLevel = iota
	EnumLevelUser
	EnumLevelClientId
	EnumLevelClientIp
)

type QpsLimiter

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

func NewQpsLimiter

func NewQpsLimiter(opts ...QpsOption) *QpsLimiter

Server ratelimiter middleware

func (*QpsLimiter) ClientIdAllow

func (l *QpsLimiter) ClientIdAllow(deviceId string) *QpsLimiter

func (*QpsLimiter) ClientIpAllow

func (l *QpsLimiter) ClientIpAllow(deviceIp string) *QpsLimiter

func (*QpsLimiter) GetOk

func (l *QpsLimiter) GetOk() bool

func (*QpsLimiter) GlobalAllow

func (l *QpsLimiter) GlobalAllow() *QpsLimiter

func (*QpsLimiter) OK

func (l *QpsLimiter) OK() bool

func (*QpsLimiter) SetOk

func (l *QpsLimiter) SetOk(ok bool)

func (*QpsLimiter) UserAllow

func (l *QpsLimiter) UserAllow(user string) *QpsLimiter

type QpsLimiterItem

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

type QpsOption

type QpsOption func(*QpsLimiter)

func QpsLimitOpt

func QpsLimitOpt(level LimitLevel, qps float64, burst int) QpsOption

WithWindow with window size.

type TpsLimiter

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

func GetTpsLimiter

func GetTpsLimiter(opts ...TpsOption) (*TpsLimiter, error)

func (*TpsLimiter) Release

func (tl *TpsLimiter) Release(n int) int

func (*TpsLimiter) TryAcquire

func (tl *TpsLimiter) TryAcquire(n int) bool

type TpsOption

type TpsOption func(*TpsLimiter)

func WithParal

func WithParal(paral int) TpsOption

func WithTag

func WithTag(tag string) TpsOption

WithWindow with window size.

Jump to

Keyboard shortcuts

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