Skip to content

Commit

Permalink
Edited Info structure in redis.go file. Edited the example in README.…
Browse files Browse the repository at this point in the history
…md file.
  • Loading branch information
sercanarga authored Feb 22, 2023
1 parent 2c1ce27 commit b089895
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -50,13 +51,15 @@ 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,
}
}
}
return Info{
Limit: s.limit,
RateLimited: true,
ResetTime: time.Now().Add(time.Duration((s.rate - (time.Now().Unix() - ts)) * time.Second.Nanoseconds())),
RemainingHits: 0,
Expand All @@ -74,13 +77,15 @@ 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),
}
}
}
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),
Expand Down

0 comments on commit b089895

Please sign in to comment.