Skip to content

added: middleware RequestIDWithCustomKey with tests#1063

Open
Danielecina wants to merge 2 commits intogo-chi:masterfrom
Danielecina:feat/added-new-requet-id-middleware-with-custom-request-id-key
Open

added: middleware RequestIDWithCustomKey with tests#1063
Danielecina wants to merge 2 commits intogo-chi:masterfrom
Danielecina:feat/added-new-requet-id-middleware-with-custom-request-id-key

Conversation

@Danielecina
Copy link
Copy Markdown

@Danielecina Danielecina commented Mar 17, 2026

Feature

Added RequestIDWithCustomKey middleware that injects a custom request ID key into the context of each request, storing it under both the default RequestIDKey and the provided custom key. This allows retrieving the request ID without the Get function via the custom key. Panics if requestIDKey is empty.

My specific use case:

  • We have an internal library of custom middlewares, and we cannot use chi middleware inside them to get the ReqID.
  • We have the chi middleware instantiated into every repository.
  • The repository has "custom middleware.Xyz" + "chimiddleware.A,b,c".
  • I need to decorate ctx with the reqIdKey and get to the other side without tertiary dependencies

I propose an abstract solution to support my case.
I'm Open to suggestions if the solution can be useful for other cases
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant