Documentation
¶
Index ¶
- func IPManager(name string) func(r *ghttp.Request)
- func PathManager(name string) func(r *ghttp.Request)
- func RateLimitMiddleware(name string) func(r *ghttp.Request)
- func SecureRequestMiddleware(name string) func(*ghttp.Request)
- func TrafficLogger(name string) func(*ghttp.Request)
- type FixedWindow
- type LeakyBucket
- type RLInterface
- type SlidingWindow
- type TokenBucket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PathManager ¶
func RateLimitMiddleware ¶
func SecureRequestMiddleware ¶
func TrafficLogger ¶
Types ¶
type FixedWindow ¶
type FixedWindow struct { WindowStart time.Time // 窗口开始时间 MaxRequests int // 窗口最大请求数 WindowSize time.Duration // 窗口大小 Counter int // 计数器 MaxCounter int // 最大计数器 BanCounter int // 封禁计数器 BanDuration int // 常规封禁时间,单位秒 // contains filtered or unexported fields }
FixedWindow 固定窗口结构体
type LeakyBucket ¶
type LeakyBucket struct { Capacity int // 桶容量 Remaining int // 当前桶里的水 LeakInterval time.Duration // 漏水速率 LastLeakTime time.Time // 上次漏水时间 Counter int // 计数器 MaxCounter int // 最大计数器 BanCounter int // 封禁计数器 BanDuration int // 常规封禁时间,单位秒 // contains filtered or unexported fields }
LeakyBucket 漏桶结构体
type RLInterface ¶
func NewRateLimiter ¶
func NewRateLimiter(ctx context.Context) RLInterface
type SlidingWindow ¶
type SlidingWindow struct { Window time.Duration // 窗口大小 MaxReq int // 最大队列数 Counter int // 计数器 MaxCounter int // 最大计数器 BanCounter int // 封禁计数器 BanDuration int // 常规封禁时间,单位秒 // contains filtered or unexported fields }
SlidingWindow 滑动窗口结构体
type TokenBucket ¶
type TokenBucket struct { Tokens int // 当前令牌数 MaxTokens int // 最大令牌数 TokensPerSecond int // 令牌生成速率 LastTime time.Time // 上个令牌生成时间 Counter int // 计数器 MaxCounter int // 最大计数器 BanCounter int // 封禁计数器 BanDuration int // 常规封禁时间,单位秒 // contains filtered or unexported fields }
TokenBucket 令牌桶结构体
Click to show internal directories.
Click to hide internal directories.