MCPcopy Create free account
hub / github.com/astercloud/aster / NewSlidingWindowLimiter

Function NewSlidingWindowLimiter

server/ratelimit/limiter.go:160–171  ·  view source on GitHub ↗

NewSlidingWindowLimiter 创建滑动窗口限流器

(limit int, windowDuration time.Duration)

Source from the content-addressed store, hash-verified

158
159// NewSlidingWindowLimiter 创建滑动窗口限流器
160func NewSlidingWindowLimiter(limit int, windowDuration time.Duration) *SlidingWindowLimiter {
161 limiter := &SlidingWindowLimiter{
162 windows: make(map[string]*window),
163 limit: limit,
164 window: windowDuration,
165 }
166
167 // 启动清理 goroutine
168 go limiter.cleanup()
169
170 return limiter
171}
172
173// Allow 检查是否允许请求
174func (l *SlidingWindowLimiter) Allow(key string) bool {

Callers 1

NewLimiterFromConfigFunction · 0.85

Calls 1

cleanupMethod · 0.95

Tested by

no test coverage detected