Documentation ¶
Index ¶
- Variables
- func DefaultGinLimitKey(c *gin.Context) string
- func DefaultGinLimitedHandler(c *gin.Context)
- func GinMemRatelimiter(conf GinRatelimiterConfig) gin.HandlerFunc
- func GinRedisRatelimiter(rdb *redis.Client, conf GinRatelimiterConfig) gin.HandlerFunc
- type GinRatelimiterConfig
- type MemRatelimiter
- type RedisRatelimiter
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // MemRatelimiterCacheExpiration MemRatelimiter key 的过期时间 MemRatelimiterCacheExpiration = time.Minute * 60 // MemRatelimiterCacheCleanInterval MemRatelimiter 过期 key 的清理时间间隔 MemRatelimiterCacheCleanInterval = time.Minute * 60 )
View Source
var ( // RedisRatelimiterCacheExpiration redis ratelimiter 缓存过期时间 RedisRatelimiterCacheExpiration = time.Minute * 60 )
Functions ¶
func DefaultGinLimitKey ¶
DefaultGinLimitKey 使用客户端 IP 生成默认的限频 key
func DefaultGinLimitedHandler ¶
DefaultGinLimitedHandler 限频触发返回 429
func GinMemRatelimiter ¶
func GinMemRatelimiter(conf GinRatelimiterConfig) gin.HandlerFunc
GinMemRatelimiter 按配置信息生成进程内存限频中间件
func GinRedisRatelimiter ¶
func GinRedisRatelimiter(rdb *redis.Client, conf GinRatelimiterConfig) gin.HandlerFunc
GinRedisRatelimiter 按配置信息生成 redis 限频中间件
Types ¶
type GinRatelimiterConfig ¶
type GinRatelimiterConfig struct { // LimitKey 生成限频 key 的函数,不传使用默认的对 IP 维度进行限制 LimitKey func(*gin.Context) string // LimitedHandler 触发限频时的 handler LimitedHandler func(*gin.Context) // TokenBucketConfig 获取 token bucket 每次放入一个token的时间间隔和桶大小配置 TokenBucketConfig func(*gin.Context) (time.Duration, int) }
GinRatelimiterConfig Gin Ratelimiter 中间件的配置信息
type MemRatelimiter ¶
MemRatelimiter 进程内存 limiter
func NewMemRatelimiter ¶
func NewMemRatelimiter() *MemRatelimiter
NewMemRatelimiter 根据配置信息创建 mem limiter
type RedisRatelimiter ¶
type RedisRatelimiter struct { *redis.Client // contains filtered or unexported fields }
RedisRatelimiter redis limiter
func NewRedisRatelimiter ¶
func NewRedisRatelimiter(rdb *redis.Client) *RedisRatelimiter
NewRedisRatelimiter 根据配置创建 redis limiter
Source Files ¶
Click to show internal directories.
Click to hide internal directories.