refactor: clean up verbose and redundant comments
Trim or remove comments that: - State the obvious (function names already convey purpose) - Repeat what the code clearly shows - Are excessively long without adding value Keep comments that explain *why*, not *what*.
This commit is contained in:
parent
805e7ffdc2
commit
5b942a5fd6
11 changed files with 16 additions and 102 deletions
|
|
@ -27,19 +27,12 @@ import (
|
|||
"log/slog"
|
||||
)
|
||||
|
||||
// RateLimitConfig controls per-IP rate limiting using a sliding window counter.
|
||||
type RateLimitConfig struct {
|
||||
// Requests is the max number of requests allowed per window.
|
||||
Requests int
|
||||
// Window is the time window duration (e.g. "1m").
|
||||
Window time.Duration
|
||||
// CleanupInterval is how often stale entries are purged (default: 5m).
|
||||
Requests int
|
||||
Window time.Duration
|
||||
CleanupInterval time.Duration
|
||||
}
|
||||
|
||||
// RateLimit returns a middleware that limits requests per IP address.
|
||||
// Uses an in-memory sliding window counter. When the limit is exceeded,
|
||||
// responds with HTTP 429 and a Retry-After header.
|
||||
func RateLimit(cfg RateLimitConfig, logger *slog.Logger) func(http.Handler) http.Handler {
|
||||
requests := cfg.Requests
|
||||
if requests <= 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue