jsonrpc icon indicating copy to clipboard operation
jsonrpc copied to clipboard

Support middlewares

Open lcd1232 opened this issue 4 years ago • 4 comments

WHAT

Support middlewares

WHY

see #45

lcd1232 avatar Apr 08 '21 09:04 lcd1232

Nice contribution!

I suggest you add global middleware support. For example for logging or metrics.

To have something like this:

mr.UseMiddleware(LoggingMiddleware(logger))
mr.UseMiddleware(MetricsMiddleware(prometheus_client))

Also, some examples/docs would be nice.

kochetkov-av avatar Apr 16 '21 11:04 kochetkov-av

@lcd1232 Sorry for the code review.

Thanks for suggesting the middleware implementation. It would be nice if you could do a PR for the middleware implementation only since it is mixed with context operations as well as the middleware implementation.

As @kochetkov-av mentioned, I agree with the way he suggested. like a chi middleware, https://github.com/go-chi/chi

osamingo avatar Jun 25 '21 16:06 osamingo

@osamingo I fixed all issues

lcd1232 avatar Oct 15 '21 12:10 lcd1232

My suggestion is to add "after" middleware test if order testing, like this:

res, err := next(c, params)
buf.WriteString(s)
return res, err

kochetkov-av avatar Oct 19 '21 10:10 kochetkov-av