Skip to content

Commit

Permalink
lint 💄
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed May 9, 2024
1 parent 0249e62 commit 2915243
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2915243

Please sign in to comment.