0

I'm new to gRPC, trying to generate go code from protos and getting this error on the generated file

Generated code with issue:

//  protoc-gen-go v1.25.0
//  protoc        v3.12.3
const (
    // Verify that this generated code is sufficiently up-to-date.
    _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
    // Verify that runtime/protoimpl is sufficiently up-to-date.
    _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)

Error

Const initializer 'protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)' is not a constant

Versions:

$ sw_vers                                                                                                                                                                                                 (sadc1c/opsvisibility)
ProductName:    Mac OS X
ProductVersion: 10.15.3
BuildVersion:   19D76

$ go version
go version go1.14 darwin/amd64

$ protoc --version                                                                                                                                                                                        (sadc1c/opsvisibility)
libprotoc 3.12.3

aclowkay
  • 3,577
  • 5
  • 35
  • 66
  • Does this answer your question? [Why doesn't Golang allow const maps?](https://stackoverflow.com/questions/37984320/why-doesnt-golang-allow-const-maps) – Marc Jul 07 '20 at 11:14
  • The linked duplicate explains what can be used as a constant. Functions cannot (except for a few builtins). Use a `var` stanza instead. – Marc Jul 07 '20 at 11:15
  • It's not a code i've written, it's generated by the protoc tool – aclowkay Jul 07 '20 at 11:25
  • Ah, fair point. Duplicate flag retracted. – Marc Jul 07 '20 at 11:34

1 Answers1

1

The cause was a bad version of the package google.golang.org/protobuf The solution is to get the latest version

go get -u google.golang.org/protobuf/proto

Source: https://developers.google.com/protocol-buffers/docs/reference/go/faq#enforce-version

aclowkay
  • 3,577
  • 5
  • 35
  • 66