refactor: refactoring of code to meet all golangci-lint requirements
This commit is contained in:
@@ -33,7 +33,7 @@ func (jwtAuth JwtAuth) AuthMiddleware(next http.Handler) http.Handler {
|
||||
if r.Header.Get(header) == "" {
|
||||
logger.Error("Proxy error, missing %s header", header)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
//check allowed origin
|
||||
// check allowed origin
|
||||
if allowedOrigin(jwtAuth.Origins, r.Header.Get("Origin")) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
|
||||
}
|
||||
@@ -42,7 +42,6 @@ func (jwtAuth JwtAuth) AuthMiddleware(next http.Handler) http.Handler {
|
||||
|
||||
}
|
||||
}
|
||||
//token := r.Header.Get("Authorization")
|
||||
authURL, err := url.Parse(jwtAuth.AuthURL)
|
||||
if err != nil {
|
||||
logger.Error("Error parsing auth URL: %v", err)
|
||||
|
||||
@@ -29,8 +29,6 @@ func (rl *TokenRateLimiter) RateLimitMiddleware() mux.MiddlewareFunc {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if !rl.Allow() {
|
||||
logger.Error("Too many requests from IP: %s %s %s", getRealIP(r), r.URL, r.UserAgent())
|
||||
//RespondWithError(w, http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized), basicAuth.ErrorInterceptor)
|
||||
|
||||
// Rate limit exceeded, return a 429 Too Many Requests response
|
||||
w.WriteHeader(http.StatusTooManyRequests)
|
||||
_, err := w.Write([]byte(fmt.Sprintf("%d Too many requests, API requests limit exceeded. Please try again later", http.StatusTooManyRequests)))
|
||||
@@ -75,7 +73,7 @@ func (rl *RateLimiter) RateLimitMiddleware() mux.MiddlewareFunc {
|
||||
|
||||
if client.RequestCount > rl.requests {
|
||||
logger.Error("Too many requests from IP: %s %s %s", clientIP, r.URL, r.UserAgent())
|
||||
//Update Origin Cors Headers
|
||||
// Update Origin Cors Headers
|
||||
if allowedOrigin(rl.origins, r.Header.Get("Origin")) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
|
||||
}
|
||||
|
||||
@@ -26,13 +26,12 @@ import (
|
||||
|
||||
// RateLimiter defines requests limit properties.
|
||||
type RateLimiter struct {
|
||||
requests int
|
||||
id string
|
||||
window time.Duration
|
||||
clientMap map[string]*Client
|
||||
mu sync.Mutex
|
||||
origins []string
|
||||
//hosts []string
|
||||
requests int
|
||||
id string
|
||||
window time.Duration
|
||||
clientMap map[string]*Client
|
||||
mu sync.Mutex
|
||||
origins []string
|
||||
redisBased bool
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user