2024-06-20 11:50:38 +08:00
|
|
|
// Package abstract ...
|
|
|
|
//
|
|
|
|
// Description : abstract ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2024-06-20 11:33
|
|
|
|
package abstract
|
|
|
|
|
2024-06-20 18:32:16 +08:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"git.zhangdeman.cn/zhangdeman/rate_limit/define"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
)
|
2024-06-20 11:50:38 +08:00
|
|
|
|
|
|
|
// IRateLimit 流控实现接口约束
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 11:33 2024/6/20
|
|
|
|
type IRateLimit interface {
|
2024-06-20 18:32:16 +08:00
|
|
|
// 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
|
|
|
|
SetRedisClient(client *redis.ClusterClient) // 设置redis客户端
|
|
|
|
AllowN(ctx context.Context, limitCfg *define.LimitConfig, tokenCnt int) (bool, error) // 申请N个令牌, N >= 0
|
|
|
|
Reset(ctx context.Context, limitCfg *define.LimitConfig) error // 重置
|
2024-06-20 11:50:38 +08:00
|
|
|
}
|