Skip to content

refactor: unify rate limiter stores behind a generic seam#131

Merged
allisson merged 2 commits into
mainfrom
improve-rate-limit
May 25, 2026
Merged

refactor: unify rate limiter stores behind a generic seam#131
allisson merged 2 commits into
mainfrom
improve-rate-limit

Conversation

@allisson
Copy link
Copy Markdown
Owner

Summary

  • Replace two structurally identical token-bucket store implementations (rateLimiterStore keyed by uuid.UUID and tokenRateLimiterStore keyed by string) with a single generic rateLimiterStore[K comparable] in a new rate_limiter.go file
  • The shared getLimiter, cleanupStale, and newRateLimitMiddleware factory live once; RateLimitMiddleware and TokenRateLimitMiddleware become thin adapters (each ~10 lines) that supply a key extractor, log attribute, and message strings
  • Any future bug in the store logic (cleanup goroutine, limiter lifecycle) is fixed in one place

Test plan

  • make test — all unit tests pass (147 in the auth/http package)
  • make lint — no issues
  • Goroutine leak tests still pass for both middleware functions

🤖 Generated with Claude Code

allisson and others added 2 commits May 25, 2026 09:50
Replace two structurally identical token-bucket store implementations
(rateLimiterStore keyed by uuid.UUID and tokenRateLimiterStore keyed by
string) with a single generic rateLimiterStore[K comparable]. The shared
getLimiter and cleanupStale logic now lives once; the two public middleware
functions become thin adapters that supply a key extractor, a log
attribute builder, and their message strings to a shared
newRateLimitMiddleware factory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@allisson allisson merged commit 56da378 into main May 25, 2026
3 checks passed
@allisson allisson deleted the improve-rate-limit branch May 25, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant