事情是这样的:我参考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 yourproto
package version), one option isGIT_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