feat: add Redis based rate limiting for multiple instances

This commit is contained in:
Jonas Kaninda
2024-11-14 13:17:28 +01:00
parent a874d14194
commit 5951616153
11 changed files with 99 additions and 150 deletions

View File

@@ -30,7 +30,7 @@ func (blockList AccessListMiddleware) AccessMiddleware(next http.Handler) http.H
for _, block := range blockList.List {
if isPathBlocked(r.URL.Path, util.ParseURLPath(blockList.Path+block)) {
logger.Error("%s: %s access forbidden", getRealIP(r), r.URL.Path)
RespondWithError(w, http.StatusForbidden, fmt.Sprintf("%d you do not have permission to access this resource", http.StatusForbidden), blockList.ErrorInterceptor)
RespondWithError(w, http.StatusForbidden, fmt.Sprintf("%d you do not have permission to access this resource"))
return
}
}
@@ -54,7 +54,7 @@ func isPathBlocked(requestPath, blockedPath string) bool {
return false
}
// NewRateLimiter creates a new rate limiter with the specified refill rate and token capacity
// NewRateLimiter creates a new requests limiter with the specified refill requests and token capacity
func NewRateLimiter(maxTokens int, refillRate time.Duration) *TokenRateLimiter {
return &TokenRateLimiter{
tokens: maxTokens,