From 2915243dfbc88c0b2ffb6ed6e140c4f74a36c8be Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Thu, 9 May 2024 20:16:17 +0200 Subject: [PATCH] =?UTF-8?q?lint=20=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/middleware.go b/middleware.go index 5044912..d74d6ba 100644 --- a/middleware.go +++ b/middleware.go @@ -13,10 +13,11 @@ import ( "go.opentelemetry.io/otel/trace" ) -const ( - customAttributesCtxKey = "slog-http.custom-attributes" - requestIDCtx = "slog-http.request-id" -) +type customAttributesCtxKeyType struct{} +type requestIDCtxKeyType struct{} + +var customAttributesCtxKey = customAttributesCtxKeyType{} +var requestIDCtxKey = requestIDCtxKeyType{} var ( TraceIDKey = "trace-id" @@ -119,7 +120,7 @@ func NewWithConfig(logger *slog.Logger, config Config) func(http.Handler) http.H requestID = uuid.New().String() r.Header.Set(RequestIDHeaderKey, requestID) } - r = r.WithContext(context.WithValue(r.Context(), requestIDCtx, requestID)) + r = r.WithContext(context.WithValue(r.Context(), requestIDCtxKey, requestID)) } // dump request body @@ -253,7 +254,7 @@ func NewWithConfig(logger *slog.Logger, config Config) func(http.Handler) http.H // GetRequestID returns the request identifier func GetRequestID(r *http.Request) string { - requestID := r.Context().Value(requestIDCtx) + requestID := r.Context().Value(requestIDCtxKey) if id, ok := requestID.(string); ok { return id }