feat(middlewares): Continue adding std middlewares
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Matthieu 'JP' DERASSE
2023-01-29 15:56:09 +00:00
parent b517779842
commit d880059980
8 changed files with 61 additions and 8 deletions

View File

@ -54,6 +54,7 @@ func NewRecoveryMiddleware(h http.Handler, recoveryFunc recoveryFuncSignature) h
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusInternalServerError)
//nolint:errcheck,gosec // we already are in a bad case scenario...
w.Write([]byte(
fmt.Sprintf("{\"code\":%d,\"message\":\"An error happened during the execution of your request.\"}", http.StatusInternalServerError),
))

View File

@ -3,6 +3,7 @@ package middleware
import (
"net/http"
"git.dev.m-and-m.ovh/mderasse/gocommon/commonctx"
"github.com/google/uuid"
)
@ -19,7 +20,9 @@ func (rm *requestIDMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
requestID = uuid.New().String()
}
// XXX: Add request_id to the context, push the context to r & edit logger middleware to add the request_id as fields
// add requestID to context and update request
ctx := commonctx.AddRequestID(r.Context(), requestID)
r = r.WithContext(ctx)
// add the request ID to the response query
w.Header().Set(requestIDHeaderKey, requestID)