Is there any way to config public route and auth route in gRPC gateway similar to other http frameworks. For example in echo
framework we can config like this
func main() {
e := echo.New()
authRoute := e.Group("/auth", middlewares.Verify)
publicRoute := e.Group("/")
// ...
}
in grpc-gateway, I have config like this.
func run() error {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// Register gRPC server endpoint
// Note: Make sure the gRPC server is running properly and accessible
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux, *grpcServerEndpoint, opts)
if err != nil {
return err
}
// Start HTTP server (and proxy calls to gRPC server endpoint)
return http.ListenAndServe(":8081", mux)
}
Is there any way to make mux
with authenticated decorator function for specific routes. And function RegisterYourServiceHandlerFromEndpoint
will register it
authenMux := runtime.NewServeMux()
// make it with authenticated func
//....
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, authenMux, *grpcServerEndpoint, opts)
I'm unsure about your specific goal, but if you only want to customize the gRPC-gateway, you can follow this approach. Alternatively, you can transfer the logic to a separate function.