Revert to Earlier Version of protoc-gen-go

5k views Asked by At

I'm attempting to compile from protobuf files into golang. After compilation, I see this in the generated 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

// 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. How can I compile so it has ProtoPackage at Version 3?

1

There are 1 answers

0
dmaixner On

Problem seems to be with old version of 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

I would recommend to update to newer version, since e.g. googleapis are relying on newer version too. See 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. You can see similar issue with steps here: https://github.com/golang/protobuf/issues/1090