首先搭建grpc环境
- brew install protobuf:安装protoc命令
- go get -u github.com/golang/protobuf/proto
- go get -u github.com/golang/protobuf/protoc-gen-go
执行命令生成golang代码
protoc --go_out=plugins=grpc:. *.proto
执行命令是发生错误
protoc-gen-go: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.
从错误中不难看出是因为找不到protoc-gen-go导致,好了可以确定问题方向了
解决方案
由于protoc-gen-go是通过go get安装时得到的,安装在$GOPATH/go/bin目录下
我们直接去该目录下找到protoc-gen-go,执行命令
cp protoc-gen-go /usr/local/bin/
好了大功告成
去获取我们想要的golang代码吧!!!