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
The grpc-gateway functionality supports REST ednpoint registration directly to ServeMux without using GRPC-server. Accordingly, interceptors for grpc are not called and HTTP route pattern is set at the moment of service method call. So we have to wrap ServeMux in custom middleware for logging, metrics, authorization and the like. The solution works quite well, but it has 2 significant drawbacks:
the ability to determine an existing route before the middleware is triggered is lost. That is, the API client can send requests via non-existent routes and these requests will be logged, authorized and generally perform any logic when there is no need to do so.
// register POST /hello-worlderr:=helloworld.RegisterHelloWorldServiceHandlerServer(context.Background(), serveMux, service)
iferr!=nil {
panic(err)
}
In middleware there is no possibility to get http pattern of the route before the request is executed. Pattern is placed in context.Context only after execution of the generated service method code. In fact, we get access to the route only after the request is processed.
Add Middleware(HandlerFunc) HundlerFunc type to the runtime package
Add a middlewares slice to the ServeMux structure and when adding a new route, apply middlewares to the route handler.
The struct pattern implements the String method and prints the path of the route, so it would be logical to put this object in context.Context to access it from middleware
The text was updated successfully, but these errors were encountered:
Thanks for the issue! I'm sympathetic to this, but I'm worried that it will cause confusion to users who are not using the direct-to-implementation pattern. It's cool that this makes it easier to use the direct-to-implementation functionality, but we have to be careful in the implementation of the new API and options to avoid confusing users.
🚀 Feature
PR
#4290
Problem
The grpc-gateway functionality supports REST ednpoint registration directly to ServeMux without using GRPC-server. Accordingly, interceptors for grpc are not called and HTTP route pattern is set at the moment of service method call. So we have to wrap ServeMux in custom middleware for logging, metrics, authorization and the like. The solution works quite well, but it has 2 significant drawbacks:
Solution
Middleware(HandlerFunc) HundlerFunc
type to the runtime packageThe text was updated successfully, but these errors were encountered: