rate_limit

package
v0.5.25 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const LimitLuaScript = `` /* 249-byte string literal not displayed */
View Source
const (
	RateLimitIP = "rate:limit:ip_"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Options)

func WithBurstLimit

func WithBurstLimit(burstLimit int) Option

func WithRateLimit

func WithRateLimit(rateLimit int) Option

func WithRateLimitWindow

func WithRateLimitWindow(rateLimitWindow int) Option

type Options

type Options struct {
	RateLimit       int // 每秒允许的最大请求数
	BurstLimit      int // 最大突发请求数
	RateLimitWindow int // 速率限制窗口大小,单位秒
}

type RateLimit

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

func New added in v0.4.0

func New(options ...Option) *RateLimit

func (*RateLimit) Provide added in v0.4.0

func (r *RateLimit) Provide(ctx context.Context) any

func (*RateLimit) RateLimit

func (r *RateLimit) RateLimit(key string) (bool, error)

Jump to

Keyboard shortcuts

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