diff --git a/README.md b/README.md index 79504a9..be64c52 100644 --- a/README.md +++ b/README.md @@ -117,12 +117,14 @@ type CustomStore struct { func (s *CustomStore) Limit(key string, c *gin.Context) Info { if UserWentOverLimit { return Info{ + Limit: 100, RateLimited: true, ResetTime: reset, RemainingHits: 0, } } return Info{ + Limit: 100, RateLimited: false, ResetTime: reset, RemainingHits: remaining, diff --git a/redis.go b/redis.go index 9ad1206..24b3a9d 100644 --- a/redis.go +++ b/redis.go @@ -38,6 +38,7 @@ func (s *redisStoreType) Limit(key string, c *gin.Context) Info { } if s.skip != nil && s.skip(c) { return Info{ + Limit: s.limit, RateLimited: false, ResetTime: time.Now().Add(time.Duration((s.rate - (time.Now().Unix() - ts)) * time.Second.Nanoseconds())), RemainingHits: s.limit - uint(hits), @@ -50,6 +51,7 @@ func (s *redisStoreType) Limit(key string, c *gin.Context) Info { panic(err) } else { return Info{ + Limit: s.limit, RateLimited: false, ResetTime: time.Now().Add(time.Duration((s.rate - (time.Now().Unix() - ts)) * time.Second.Nanoseconds())), RemainingHits: 0, @@ -57,6 +59,7 @@ func (s *redisStoreType) Limit(key string, c *gin.Context) Info { } } return Info{ + Limit: s.limit, RateLimited: true, ResetTime: time.Now().Add(time.Duration((s.rate - (time.Now().Unix() - ts)) * time.Second.Nanoseconds())), RemainingHits: 0, @@ -74,6 +77,7 @@ func (s *redisStoreType) Limit(key string, c *gin.Context) Info { panic(err) } else { return Info{ + Limit: s.limit, RateLimited: false, ResetTime: time.Now().Add(time.Duration((s.rate - (time.Now().Unix() - ts)) * time.Second.Nanoseconds())), RemainingHits: s.limit - uint(hits), @@ -81,6 +85,7 @@ func (s *redisStoreType) Limit(key string, c *gin.Context) Info { } } return Info{ + Limit: s.limit, RateLimited: false, ResetTime: time.Now().Add(time.Duration((s.rate - (time.Now().Unix() - ts)) * time.Second.Nanoseconds())), RemainingHits: s.limit - uint(hits),