简体   繁体   English

恢复到早期版本的 protoc-gen-go

[英]Revert to Earlier Version of protoc-gen-go

I'm attempting to compile from protobuf files into golang.我正在尝试从 protobuf 文件编译成 golang。 After compilation, I see this in the generated pb.go编译后,我在生成的 pb.go 中看到了这个

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
//  protoc-gen-go v1.23.0
//  protoc        v3.12.3

and

// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4

However, previously generated pb.go have但是,之前生成的 pb.go 有

// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package

With version 4 of the proto package the code breaks.使用 proto 包的第 4 版,代码会中断。 How can I compile so it has ProtoPackage at Version 3?我如何编译才能在版本 3 中使用 ProtoPackage?

Problem seems to be with old version of protobuf lib.问题似乎出在旧版本的protobuf lib 上。 ProtoPackageIsVersion3 is for 1.3.* and ProtoPackageIsVersion4 is for 1.4+, you can see the update here: https://github.com/golang/protobuf/releases/tag/v1.4.0 ProtoPackageIsVersion3适用于 1.3.*, ProtoPackageIsVersion4适用于 1.4+,您可以在此处查看更新: https : //github.com/golang/protobuf/releases/tag/v1.4.0

I would recommend to update to newer version, since eg googleapis are relying on newer version too.我建议更新到较新的版本,因为例如 googleapis 也依赖于较新的版本。 See https://developers.google.com/protocol-buffers/docs/reference/go/faq#enforce-version-apiv1请参阅https://developers.google.com/protocol-buffers/docs/reference/go/faq#enforce-version-apiv1

If, for some reason, you still need to use older version of everything, you would need protobuf of version 1.3.5 and most likely manually build proto-gen-go and protoc to match.如果出于某种原因,您仍然需要使用旧版本的所有内容,则需要 1.3.5 版的protobuf ,并且很可能手动构建proto-gen-goprotoc以匹配。 You can see similar issue with steps here: https://github.com/golang/protobuf/issues/1090您可以在此处看到类似的步骤问题: https : //github.com/golang/protobuf/issues/1090

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM