Documentation ¶
Index ¶
- Variables
- func Limiter() gin.HandlerFunc
- func LocalLimiter() gin.HandlerFunc
- func LocalLimiterV2() gin.HandlerFunc
- func NewDelayLimiter(limit Waiter) gin.HandlerFunc
- func NewErrorLimiter(limit Allower) gin.HandlerFunc
- func RedisLimiter() gin.HandlerFunc
- type Allower
- type CheckFn
- type LimitBase
- type LimitInterface
- type LocalLimit
- type LocalLimitV2
- type RedisLimit
- type Waiter
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrLimited = errors.New("rate limit exceeded")
Functions ¶
func Limiter ¶
func Limiter() gin.HandlerFunc
func LocalLimiter ¶
func LocalLimiter() gin.HandlerFunc
func LocalLimiterV2 ¶
func LocalLimiterV2() gin.HandlerFunc
func NewDelayLimiter ¶
func NewDelayLimiter(limit Waiter) gin.HandlerFunc
NewDelayLimiter 达到限流阈值后持有相关请求并等到执行
func NewErrorLimiter ¶
func NewErrorLimiter(limit Allower) gin.HandlerFunc
NewErrorLimiter 达到限流阈值后直接报错
func RedisLimiter ¶
func RedisLimiter() gin.HandlerFunc
Types ¶
type Allower ¶
type Allower interface {
Allow() bool
}
Allower rate.NewLimiter(rate.Every(time.Minute), 1)
type LimitBase ¶
type LimitBase struct { LimitInterface // Expire key 过期时间 Expire int // Limit 周期时间 Limit int }
type LimitInterface ¶
type LocalLimit ¶
type LocalLimit struct { LimitBase // contains filtered or unexported fields }
func (*LocalLimit) CheckOrMark ¶
func (l *LocalLimit) CheckOrMark(key string, expire int, limit int) error
type LocalLimitV2 ¶
type LocalLimitV2 struct { LimitBase // contains filtered or unexported fields }
func (*LocalLimitV2) CheckOrMark ¶
func (l *LocalLimitV2) CheckOrMark(key string, expire int, limit int) error
type RedisLimit ¶
type RedisLimit struct { LimitBase // contains filtered or unexported fields }
func (*RedisLimit) CheckOrMark ¶
func (l *RedisLimit) CheckOrMark(key string, expire int, limit int) error
Click to show internal directories.
Click to hide internal directories.