我是gRPC的新手,尝试从protos生成go代码,并在生成的文件上获取此错误
产生问题的代码:
// 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)
)
错误Const initializer 'protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)' is not a constant
版本:$ 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
最佳答案
原因是软件包google.golang.org/protobuf
的版本错误
解决方案是获取最新版本go get -u google.golang.org/protobuf/proto
资料来源:https://developers.google.com/protocol-buffers/docs/reference/go/faq#enforce-version
关于go - 常量初始化器'protoimpl.EnforceVersion(20-protoimpl.MinVersion)'不是常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62773793/