-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
[FEATURE REQUEST] Handler function middleware #104
Comments
@rugwirobaker Thanks for this feature request! Could you provide an example code for a potential API for middleware support? Alternatively, can you simply write a middleware function and wrap your handlers with that middleware? func loggingMiddleware(h asynq.Handler) asynq.Handler {
return asynq.HandlerFunc(func(ctx context.Context, t *asynq.Task) error {
// log something before handler processes the task
h.ProcessTask(ctx, t)
// log something after handler processed the task
})
}
mux := asynq.ServeMux()
mux.HandleFunc("something", loggingMiddleware(myHandler)) would that work? Or should the package offer better support for middleware chain? |
For most use cases this works fine but in cases where you have a lot of middleware functions having something like: |
Ok that makes sense. Example: mux := asynq.ServeMux()
mux.Use(loggingMiddleware)
mux.HandleFunc("something", myHandler) |
Is your feature request related to a problem? Please describe.
Do plan to support middleware functions that behave the same way for example gorilla mux.Middware do? If not how do logging??
The text was updated successfully, but these errors were encountered: