You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm facing a challenge where I need to extract specific data from a gRPC handler into my HTTP middleware. Despite thoroughly reviewing the documentation, I couldn't find a suitable answer. In my current implementation, I've utilized WithForwardResponseOption in runtime.NewServeMux to inject values into the HTTP response headers and subsequently retrieve them in the middleware. However, I find this solution somewhat inelegant, are there any other ways?
funcMetrics(next http.Handler) http.Handler {
returnhttp.HandlerFunc(func(w http.ResponseWriter, r*http.Request) {
timeStart:=time.Now()
next.ServeHTTP(w, r)
// here it is supposed to record metrics and for them you need to get certain values from the grpc handler
})
}
I'm trying to achieve something similar, I think it would be beneficial to have something like a functional interface for wrapping mux.Handle and mux.HandlePath, alternatively it would be also possible for the generated code to contain some capability of wrapping the call to mux.Handle there.
I'm trying to add support in go-http-metrics for the runtime mux, and although I can do this easily for custom methods, there are no viable alternatives of conciliating these two libraries. In my case if I went for a solution close to what @LazarenkoA has done here, it would be senseless to use go-http-metrics.
What you're suggesting is the only way I know of to pass extra information from gRPC handlers into HTTP middleware. I don't think this is too rare of a use case (e.g., setting cookies from gRPC handlers) so I'd be interested in exploring the solution space, if you're interested in working on it.
I'm facing a challenge where I need to extract specific data from a gRPC handler into my HTTP middleware. Despite thoroughly reviewing the documentation, I couldn't find a suitable answer. In my current implementation, I've utilized WithForwardResponseOption in runtime.NewServeMux to inject values into the HTTP response headers and subsequently retrieve them in the middleware. However, I find this solution somewhat inelegant, are there any other ways?
here's how I tried to solve this problem:
on the grpc handler side
The text was updated successfully, but these errors were encountered: