Files
CamTalk/backend/internal/ratelimit/limiter.go

18 lines
428 B
Go
Raw Normal View History

package ratelimit
import (
"context"
"time"
)
// Limiter 速率限制器接口。
type Limiter interface {
// Allow 判断 key 是否允许执行一次操作。
// key 通常为 "userID:action" 格式。
// 返回 (allowed, retryAfter)。retryAfter 表示需要等待的时间。
Allow(ctx context.Context, key string) (bool, time.Duration)
// Stop 停止限流器,清理资源(如后台 goroutine
Stop()
}