簡體   English   中英

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

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

我正在嘗試從 protobuf 文件編譯成 golang。 編譯后,我在生成的 pb.go 中看到了這個

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

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

但是,之前生成的 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

使用 proto 包的第 4 版,代碼會中斷。 我如何編譯才能在版本 3 中使用 ProtoPackage?

問題似乎出在舊版本的protobuf lib 上。 ProtoPackageIsVersion3適用於 1.3.*, ProtoPackageIsVersion4適用於 1.4+,您可以在此處查看更新: https : //github.com/golang/protobuf/releases/tag/v1.4.0

我建議更新到較新的版本,因為例如 googleapis 也依賴於較新的版本。 請參閱https://developers.google.com/protocol-buffers/docs/reference/go/faq#enforce-version-apiv1

如果出於某種原因,您仍然需要使用舊版本的所有內容,則需要 1.3.5 版的protobuf ,並且很可能手動構建proto-gen-goprotoc以匹配。 您可以在此處看到類似的步驟問題: https : //github.com/golang/protobuf/issues/1090

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM