rateLimitKit

package
v3.0.37 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NewLimiter 限流器,基于令牌桶算法(Token Bucket).
	/*
		PS: 初始状态下,令牌桶是满的.

		@param r 每秒生成的令牌数,(1) 可以直接是 某个数值; (2) 也可以是 rate.Every() 的返回值;
		@param b 令牌桶的容量

		e.g.
		// 初始化 limiter 每秒10个令牌,令牌桶容量为20
		limiter := rate.NewLimiter(rate.Every(time.Millisecond*100), 20)
	*/
	NewLimiter func(r rate.Limit, b int) *rate.Limiter = rate.NewLimiter
)

Functions

func NewGinMiddleware

func NewGinMiddleware(r rate.Limit, b int, forbiddenText string) gin.HandlerFunc

NewGinMiddleware Gin的限流器,用于限流.

PS: 传参说明详见 NewLimiter.

@param r 每秒生成的令牌数, (1) 可以直接是 某个数值;

(2) 也可以是 rate.Every() 的返回值;

@param b 令牌桶的容量 @param forbiddenText 被限流时,响应给前端的内容(状态码固定为 403)

Types

This section is empty.

Jump to

Keyboard shortcuts

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