流控接口定义 + 基于redis的流控实现

This commit is contained in:
2024-06-20 11:50:38 +08:00
parent f093b5c8ef
commit e4bd913390
4 changed files with 199 additions and 0 deletions

25
abstract/limit.go Normal file
View File

@ -0,0 +1,25 @@
// Package abstract ...
//
// Description : abstract ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-06-20 11:33
package abstract
import "context"
// IRateLimit 流控实现接口约束
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:33 2024/6/20
type IRateLimit interface {
Second(ctx context.Context, key string, total, rate int) (bool, error) // 每秒访问次数限制
Minute(ctx context.Context, key string, total, rate int) (bool, error) // 每分钟访问次数限制
Hour(ctx context.Context, key string, total, rate int) (bool, error) // 每小时访问次数限制
Day(ctx context.Context, key string, total, rate int) (bool, error) // 每天访问次数限制
Month(ctx context.Context, key string, total, rate int) (bool, error) // 每月访问次数限制
Year(ctx context.Context, key string, total, rate int) (bool, error) // 每年访问次数限制
Custom(ctx context.Context, timeInfo int64, key string, total, rate int) (bool, error) // 自定义指定时间内的访问次数, timeInfo 单位 : s
}