Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set context in middleware & capture responses #12

Closed
trajan0x opened this issue Jun 27, 2024 · 1 comment · Fixed by #16
Closed

Ability to set context in middleware & capture responses #12

trajan0x opened this issue Jun 27, 2024 · 1 comment · Fixed by #16

Comments

@trajan0x
Copy link

Ability to inherit context in middleware

Right now, command middleware is pretty limited because:

  1. It can not capture the responses in any way. Traditionally, in an http middleware I could do something like this:
	return func(handler slacker.CommandHandler) slacker.CommandHandler {
		return func(cmdCtx *slacker.CommandContext) {
                      ctx := context.WithValue(cmdCtx.Context(), "test", "value")
                     // in gin this would be c.Request.WithContext (or c.WithContext in net/http
                      cmdCtx.WithContext(ctx)
                      next()
                     // within the next method I could query this context
		}
	}

There's nothing like that at all. For an example use case, you could do thing s like otel with this. I've put together an example here w/o the context pass down

It would also be very standard to be able to capture the response after next() is called.

This could either be done by overwriting the writer, or with a hook on reply

@raed-shomali
Copy link
Contributor

Would you be open to putting together a PR to address this?

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 a pull request may close this issue.

2 participants