go - 常量初始化器'protoimpl.EnforceVersion(20-protoimpl.MinVersion)'不是常量

标签 go protocol-buffers protoc grpc-go

我是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/

相关文章:

go - 为什么 struct Client(在 coreos/etcd/clientv3/client.go 中)有 PUT 方法

postgresql - 使用 xo 从 postgres 数据库表模式生成 DTO 结构

Google 使用 Golang 进行身份验证和授权

python - 由于 "TypeError: unhashable type: ' bytearray'"(在树莓派中)导致消息被截断

java - Hadoop 3.1构建在 `protoc --version`失败

go - 扫描查询 2 个参数

c++ - Proto 文件对其他 proto 文件的依赖

networking - protobuf需要网络数据包头吗?

python - 训练元图的权重和偏差

python - 查找自定义 protobuf 插件时出错