• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

使用goprotoc--go_out输出的*.pb.go文件时报undefined:proto.ProtoPackageIsVersion3 ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

事情是这样的:我参考go的 grpc 实现 https://grpc.io/docs/quickstart/go/

Download the example

The grpc code that was fetched with go get google.golang.org/grpc also contains the examples. They can be found under the examples dir: $GOPATH/src/google.golang.org/grpc/examples.

根据教程一步一部执行helloword demo 重新转换修改后的 helloword.proto 文件至 helloword.go.proto 文件后

protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld

再执行 

go run greeter_server/main.go

就报错

helloworld\helloworld.pb.go:25:11: undefined: proto.ProtoPackageIsVersion3

通过 go get -u google.golang.org/grpc 安装的 protoc-gen-go版本永远是最新的(支持v3)

而使用grpc教程 demo 用的包是 protoc-gen-go v1.2.0 版本 (不支持v3 )

 go get -u google.golang.org/grpc

 

如何切换安装 v1.2.0版本?

If you need a particular version of protoc-gen-go (e.g., to match your proto package version), one option is

GIT_TAG="v1.2.0" # change as needed
go get -d -u github.com/golang/protobuf/protoc-gen-go
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
go install github.com/golang/protobuf/protoc-gen-go

 

参考:https://stackoverflow.com/questions/53952723/undefined-proto-protopackageisversion3


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap