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

rpc/v2 middleware #50

Open
cv21 opened this issue May 1, 2017 · 6 comments
Open

rpc/v2 middleware #50

cv21 opened this issue May 1, 2017 · 6 comments

Comments

@cv21
Copy link

cv21 commented May 1, 2017

When I writing rpc server based on rpc/v2, I need to use middleware for logging or, for example, for writing some metrics. I can use handlerFunc middlewares in style

type Log struct {
	L *log.Logger
}

func (m *Log) Use(next http.Handler) http.Handler {
	return http.HandlerFunc(func(r http.ResponseWriter, req *http.Request) {
		m.L.Println("Incoming request start")
		next.ServeHTTP(r, req)
		m.L.Println("Incoming request end")
	})
}

But it is not comfortably. I would like to know rpc method name and parsed request.
Just in rpc server (not v2) I found RegisterBeforeFunc that looking helpful, but in v2 it is not exist.

Please, suggest me how can I solve that problem?

@tejasmanohar
Copy link

+💯 for a system of middleware. I ran into a similar situation and came looking for a solution. It'd be incredibly useful for implementing standard logging as well as other application conventions.

@elithrar
Copy link
Contributor

elithrar commented May 15, 2017 via email

@tejasmanohar
Copy link

Sounds good! ... But, now that I think of it, is there anything that can't be done with BeforeFunc / AfterFunc model atm? I think the main change would be exposing things like parsed request/response on the Before and After rather than just metadata like RequestInfo

Would you all be open to this? I can PR to show what I mean. It shouldn't have to be a breaking change... we can just add nill-able req/res fields to RequestInfo. Would this also solve your use case, @cv21 ?

@prisamuel
Copy link

Just in rpc server (not v2) I found RegisterBeforeFunc that looking helpful, but in v2 it is not exist

At dotmesh.com we use gorilla/rpc and this was a feature I required to send out metrics to via prometheus instrumentation.

I've added RegisterBeforeFunc, RegisterAfterFunc, and RegisterInterceptFunc into v2 on a fork here. Will submit a PR shortly.

@Oppodelldog
Copy link

Oppodelldog commented Jan 16, 2019

I was just looking for this capability and as I found the feature request might have been resolved since the named hooks are already merged.

From code review I'd say this issue can be closed.

@the729
Copy link

the729 commented Nov 15, 2022

You can write a Codec wrapper which acts like a middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

7 participants