diff --git a/redispattern/slidingwindowratelimiter/sliding_window_rate_limiter.go b/redispattern/slidingwindowratelimiter/sliding_window_rate_limiter.go index 80dcdff..cb6d1b7 100644 --- a/redispattern/slidingwindowratelimiter/sliding_window_rate_limiter.go +++ b/redispattern/slidingwindowratelimiter/sliding_window_rate_limiter.go @@ -30,13 +30,6 @@ return limit - count ` ) -var errLimitHit = errors.New("limit hit") - -// IsLimitHit detects a limit condition. -func IsLimitHit(err error) bool { - return errors.Is(err, errLimitHit) -} - func scriptDigest() (string, error) { s := sha1.New() _, err := io.WriteString(s, script) @@ -87,10 +80,10 @@ func (sl *SlidingWindowRateLimiter) Allow() (bool, error) { } switch v := ret.(type) { case int64: - if v == 0 { - return false, errLimitHit + if v <= 0 { + return false, errors.New("limit reached") } - return v > 0, nil + return true, nil default: return false, fmt.Errorf("sliding window rate limiter err: %#v, key = %s, window = %s, limit = %d", ret, sl.key, sl.window, sl.limit) }