Skip to content

Commit

Permalink
feat: add GetRequestIDFromContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsAreku committed Jul 7, 2024
1 parent de72e88 commit cc0678b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ 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(requestIDCtxKey)
return GetRequestIDFromContext(r.Context())
}

// GetRequestID returns the request identifier from the context
func GetRequestIDFromContext(ctx context.Context) string {
requestID := ctx.Value(requestIDCtxKey)
if id, ok := requestID.(string); ok {
return id
}
Expand Down

0 comments on commit cc0678b

Please sign in to comment.