如何维护原始文件? [英] How to Maintain Proto Files?

查看:89
本文介绍了如何维护原始文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了3个原型文件,并希望将其保存在git repo中:

I've created 3 proto files and would like to keep it in a git repo:

与所有其他文件分开. 存储库仅包含.proto个文件.我有3个微服务,每个微服务都有自己的存储库,这些存储库使用这些原始文件相互通信:

separated from all others files. The repository contains only .proto files. I have 3 microservices and each of them has their own repository that is using those proto files to communicate with each others:

您可以在上面的图片中看到,原始文件正在使用不同的微服务.

You can see on the picture above, that proto files are consuming from different microservices.

假设,我要更改 Protofile2 并将更改推送到proto存储库,请记住proto文件存储库与微服务存储库是分开的:

Assume, I am going to change the Protofile2 and push the changes to proto repository, remember proto files repository are separated from microservices repository:

当我在 service1 service2 上运行go test时,它应该告诉我 Protofile2 已更改或没有相同的内容类似于proto文件在service2文件夹中的哈希:

When I run go test on service1 or service2, it should tell me, that Protofile2 has changed or does not have the same hash like proto file in the service2 folder:

我必须再次生成代码.

是否存在解决该问题的工具?还是应该解决?

Does it exist any tools to solve the problem? Or how should I solve it?

推荐答案

这是我的建议:

  • 将您的原型(及其生成的makefile文件)存储在一个git仓库中.为了简化导入,每个定义都应位于自己的目录中
  • 用版本标记存储库-尤其是在潜在的重大更改上
  • 从您的微服务中导入特定的协议定义,例如import "github.com/me/myproto/protodef2"
  • 使用go模块(于2019年在go v1.11中引入)以确保微型-service X获得protobuf Y的兼容版本
  • Store your protos (and their go generating makefiles) in a single git repo. Each definition should be in their own directory for import simplicity
  • tag the repo with a version - especially on potentially breaking changes
  • import a particular proto defs from your micro-services e.g. import "github.com/me/myproto/protodef2"
  • use go modules (introduced with go v1.11 in 2019) to ensure micro-service X gets a compatible version of protobuf Y

要点2-正如@PaulHankin提到的-尽量不要破坏向后兼容性. Protobuf字段可以删除,但是只要其余字段的索引保持不变,旧的客户端调用仍将与新的proto defs兼容.

To point 2 - and as @PaulHankin mentioned - try not to break backward compatibility. Protobuf fields can be removed, but as long as the remaining field indices are unaltered, old client calls will still be compatible with newer proto defs.

这篇关于如何维护原始文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆