From b0898951d1b0c1f5e2c5bdfcde2dec14a01d3188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sercan=20Ar=C4=9Fa?= Date: Wed, 22 Feb 2023 08:11:53 +0300 Subject: [PATCH] Edited Info structure in redis.go file. Edited the example in README.md file. --- README.md | 2 ++ redis.go | 5 +++++ 2 files changed, 7 insertions(+) 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),