如何在运行时基于提供的proto向gRPC服务器发送客户端请求?

huangapple go评论64阅读模式
英文:

How to send client request to gRPC server during runtime based on provided proto

问题

从官方网站Go gRPC上,我们可以使用protoc和一个.proto文件生成gRPC代码。然后我们可以设置服务器并发送gRPC请求。

但是现在我想要向任何一个具有指定.proto文件的gRPC服务器发送gRPC请求。所以我应该解析.proto文件,然后发送gRPC请求到那个gRPC服务器。

有人知道如何实现吗?

非常感谢!

英文:

From official website Go gRPC, we can generate gRPC code using protoc with a .proto file. And then we can setup server and send gRPC request.

But now I want to send gRPC request to an any gRPC server with a specified '.proto' file. So I should parse the .proto file and then send gRPC request to that gRPC server.

Could any one know how to realize it?

Thank you very much!

答案1

得分: 1

你可能仍然想要生成一个客户端。gRPC的优点是静态类型。我找到了这个库(https://pkg.go.dev/github.com/jhump/protoreflect/dynamic/grpcdynamic),不确定它是否符合你的需求。我不认为Go目前支持动态库(https://stackoverflow.com/questions/18237863/is-it-possible-to-dynamically-load-go-code),所以我不确定这个实现有多容易。

英文:

You probably want to generate a client anyways. The beauty of grpc is static typing. I found this library, not sure if it is what you are looking for. I don't think that go supports dynamic libraries yet here, so I'm not sure how easy this is to implement.

huangapple
  • 本文由 发表于 2022年8月29日 15:37:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/73525514.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定