使用 go protoc --go_out 輸出的 *.pb.go文件時報 undefined: proto.ProtoPackageIsVersion3


事情是這樣的:我參考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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM