ratelimit

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BBRConfig

type BBRConfig struct {
	Enabled      bool    `mapstructure:"enabled" yaml:"enabled"`
	CPUThreshold int64   `mapstructure:"cpu_threshold" yaml:"cpu_threshold"`
	Window       int     `mapstructure:"window" yaml:"window"`
	Decay        float64 `mapstructure:"decay" yaml:"decay"`
}

type Config

type Config struct {
	Rate  float64 `mapstructure:"rate" yaml:"rate"`
	Burst int     `mapstructure:"burst" yaml:"burst"`
}

type ContextLimiter

type ContextLimiter interface {
	Limiter
	AllowContext(ctx context.Context, key string) bool
	AllowNContext(ctx context.Context, key string, n int) bool
}

type Limiter

type Limiter interface {
	Allow(key string) bool
	AllowN(key string, n int) bool
}

type Option

type Option struct {
	Rate   float64
	Burst  int
	Window time.Duration
	Limit  int
}

type PerKey

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

func NewPerKey

func NewPerKey(inner func() Limiter) *PerKey

func (*PerKey) Allow

func (p *PerKey) Allow(key string) bool

func (*PerKey) AllowContext

func (p *PerKey) AllowContext(ctx context.Context, key string) bool

func (*PerKey) AllowN

func (p *PerKey) AllowN(key string, n int) bool

func (*PerKey) AllowNContext

func (p *PerKey) AllowNContext(ctx context.Context, key string, n int) bool

Directories

Path Synopsis
Package store 提供限流状态存储后端(内存 / Redis)
Package store 提供限流状态存储后端(内存 / Redis)
Package strategy BBR 自适应限流器
Package strategy BBR 自适应限流器

Jump to

Keyboard shortcuts

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