23 lines
534 B
Go
23 lines
534 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"gitea.privcloud.tech/mtusi2026/internal/pkg/rest/headers"
|
|
)
|
|
|
|
func RequestIDMiddleware() Middleware {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
requestID := uuid.New()
|
|
w.Header().Set(headers.HeaderRequestID, requestID.String())
|
|
ctx = context.WithValue(ctx, headers.HeaderRequestID, requestID)
|
|
next.ServeHTTP(w, r.WithContext(ctx))
|
|
})
|
|
}
|
|
}
|