ratelimit

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLimitExceed is returned when the rate limiter is
	// triggered and the request is rejected due to limit exceeded.
	ErrLimitExceed = errors.New("rate limit exceeded")
)

Functions

This section is empty.

Types

type Ratelimit

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

Ratelimit implements bbr-like limiter. It is inspired by sentinel. https://github.com/alibaba/Sentinel/wiki/%E7%B3%BB%E7%BB%9F%E8%87%AA%E9%80%82%E5%BA%94%E9%99%90%E6%B5%81

func NewLimiter

func NewLimiter(ctx context.Context, name string) *Ratelimit

NewLimiter returns a bbr limiter

func (*Ratelimit) Allow

func (l *Ratelimit) Allow() (func(), error)

Allow checks all inbound traffic. Once overload is detected, it raises limit.ErrLimitExceed error.

func (*Ratelimit) Stat

func (l *Ratelimit) Stat() stat

Stat tasks a snapshot of the bbr limiter.

Jump to

Keyboard shortcuts

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