diff options
| author | soler_j <soler_j@etna-alternance.net> | 2025-05-04 21:41:04 +0200 |
|---|---|---|
| committer | soler_j <soler_j@etna-alternance.net> | 2025-05-04 21:41:04 +0200 |
| commit | 40f7e50b91374ce17b6dce514cf371e5629192eb (patch) | |
| tree | 0bd69cc56e97fd8e4e9b52b24381a01924e4d850 | |
| parent | dc3c72813a6358cde4c1bb3d1eaf618c6d46c460 (diff) | |
Ajout de la gestion des middlewares pour le logging et l'authentification, ainsi que la fonction de chaƮnage des middlewares.
| -rw-r--r-- | app/internal/utils/middleware.go (renamed from app/internal/middleware.go) | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/app/internal/middleware.go b/app/internal/utils/middleware.go index 2af90c8..5133916 100644 --- a/app/internal/middleware.go +++ b/app/internal/utils/middleware.go @@ -1,4 +1,4 @@ -package internal +package utils import ( "log" @@ -7,7 +7,6 @@ import ( "time" "github.com/golang-jwt/jwt/v5" - "github.com/ketsuna-org/bot-creator-api/internal/utils" ) func LogMiddleware(next http.Handler) http.Handler { @@ -29,7 +28,7 @@ func AuthMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { authHeader := r.Header.Get("Authorization") if authHeader == "" { - utils.RespondWithError(w, http.StatusUnauthorized, "Missing authorization header") + RespondWithError(w, http.StatusUnauthorized, "Missing authorization header") return } tokenString := authHeader[len("Bearer "):] @@ -42,14 +41,14 @@ func AuthMiddleware(next http.Handler) http.Handler { return []byte(os.Getenv("JWT_SECRET")), nil }) if err != nil { - utils.RespondWithError(w, http.StatusUnauthorized, "Invalid token") + RespondWithError(w, http.StatusUnauthorized, "Invalid token") return } if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid { // You can access claims here log.Printf("User ID: %v", claims["user_id"]) } else { - utils.RespondWithError(w, http.StatusUnauthorized, "Invalid token claims") + RespondWithError(w, http.StatusUnauthorized, "Invalid token claims") return } |
