Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 committed Mar 17, 2024
1 parent a02c6e9 commit ccf98e9
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions server/pkg/middleware/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func NewRateLimitMiddleware(discordCtrl *discord.DiscordController, limit int64,
func (r *RateLimitMiddleware) Increment() bool {
// Atomically increment the count
newCount := atomic.AddInt64(&r.count, 1)
if newCount > r.limit {
return false
}
return true
return newCount <= r.limit
}

// Stop the internal ticker, effectively stopping the rate limiter.
Expand All @@ -78,7 +75,7 @@ func rateLimiter(interval string) *limiter.Limiter {
// GlobalRateLimiter rate limits all requests to the server, regardless of the endpoint.
func (r *RateLimitMiddleware) GlobalRateLimiter() gin.HandlerFunc {
return func(c *gin.Context) {
if r.Increment() == false {
if !r.Increment() {
go r.discordCtrl.NotifyPotentialAbuse("Global rate limit breached")
c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{"error": "Rate limit breached, try later"})
return
Expand Down

0 comments on commit ccf98e9

Please sign in to comment.