feat: fixed lint errors
This commit is contained in:
@@ -8,6 +8,11 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// requestIDKey is a custom type for context key to avoid collisions
|
||||
type requestIDKey struct{}
|
||||
|
||||
var _ requestIDKey
|
||||
|
||||
// RequestIDMiddleware adds a unique request ID to each request
|
||||
func RequestIDMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -17,9 +22,9 @@ func RequestIDMiddleware(next http.Handler) http.Handler {
|
||||
// Set request ID in response header
|
||||
w.Header().Set("X-Request-ID", requestID)
|
||||
|
||||
// Add request ID to context
|
||||
// Add request ID to context using custom type
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(ctx, "request_id", requestID)
|
||||
ctx = context.WithValue(ctx, requestIDKey{}, requestID)
|
||||
|
||||
// Log the request ID assignment
|
||||
logger := logger.GetLogger()
|
||||
|
||||
Reference in New Issue
Block a user