ratelimit

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitExceed = errors.New("rate limit exceeded")

ErrLimitExceed is returned when the rate limiter rejects a request.

Functions

This section is empty.

Types

type BBR

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

BBR implements a BBR-like adaptive limiter.

func NewLimiter

func NewLimiter(opts ...Option) *BBR

NewLimiter returns a BBR limiter.

func (*BBR) Allow

func (l *BBR) Allow() (DoneFunc, error)

Allow checks whether a request is allowed.

func (*BBR) Stat

func (l *BBR) Stat() Stat

Stat returns a metrics snapshot.

type DoneFunc

type DoneFunc func(DoneInfo)

DoneFunc records request completion.

type DoneInfo

type DoneInfo struct {
	Err error
}

DoneInfo contains request completion metadata.

type Limiter

type Limiter interface {
	Allow() (DoneFunc, error)
}

Limiter is a rate limiter.

type Option

type Option func(*options)

Option configures a BBR limiter.

func WithBucket

func WithBucket(b int) Option

WithBucket sets the rolling window bucket count.

func WithCPUQuota

func WithCPUQuota(quota float64) Option

WithCPUQuota sets the real CPU quota if it differs from GOMAXPROCS.

func WithCPUThreshold

func WithCPUThreshold(threshold int64) Option

WithCPUThreshold sets the CPU threshold, scaled from 0 to 1000.

func WithWindow

func WithWindow(d time.Duration) Option

WithWindow sets the rolling window duration.

type Stat

type Stat struct {
	CPU         int64
	InFlight    int64
	MaxInFlight int64
	MinRt       int64
	MaxPass     int64
}

Stat contains a BBR metrics snapshot.

Jump to

Keyboard shortcuts

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