func RateLimitMiddleware()

in internal/middleware/rate_limiter/rate_limiter.go [16:27]


func RateLimitMiddleware(limiter *rate.Limiter, next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// Check if the request should be allowed or rate-limited
		if limiter.Allow() {
			// If allowed, call the next handler
			next(w, r)
		} else {
			// If rate-limited, return a 429 (Too Many Requests) status
			http.Error(w, "Too Many Requests", http.StatusTooManyRequests)
		}
	}
}