我可以通过参考外部URL来生成一个gRPC存根文件吗?

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

Can I generate a grpc stub file by referring to an external url?

问题

从上周开始,我开始学习gRPC / protobuf,并且我想找出最佳的微服务架构。其中一个方面是将接口定义语言(IDL)存储库单独分离出来。这样,任何服务都可以生成存根文件,而无需从另一个服务中复制/粘贴proto文件。这种做法可行吗?

英文:

I was start to learning gRPC / protobuf from last week and I wanna find out best architectures for microservices. So one of the things is to have a IDL repository separately. If so, Any service can generate stub files without proto file copy / paste from another service. Is it possible?

答案1

得分: 2

如果我没记错的话,protoc不支持通过URL引用proto文件,这是不幸的,因为这是一个合理的需求。可能是因为特定语言的代码生成实现支持这一功能。

我建议你将项目的proto文件(可能还包括从它们生成的protoc代码)发布在一个单独的(proto)仓库中。这样可以促进重用,独立版本控制,并鼓励跨语言使用。

如果proto文件被捆绑在一个包含Golang服务器实现的仓库中,要想仅克隆proto文件以生成Python客户端就更加困难。

英文:

IIRC protoc does not enable referencing protos via URL which is unfortunate as it's a reasonable requirement. It's possible that language-specific implementations of the code generation, do enable this.

I recommend you do publish a project's protos (and possibly cache code protoc-generated from them) in a separate (proto) repo. This facilitates reuse, independent versioning and encourages cross-language use.

If protos are bundled in e.g. a repo including a Golang server implementation, it's more difficult to just clone the protos in order to generate e.g. a Python client.

huangapple
  • 本文由 发表于 2021年10月9日 20:23:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/69506698.html
匿名

发表评论

匿名网友

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

确定