1. 环境配置
go环境配置(略)
1.1 protoc-gen-go
cd $GOPATH/src/github.com/golang/
git clone https://github.com/golang/protobuf.git
cd protobuf/protoc-gen-go
go build
#生成protoc-gen-go
go install .
#or
cp protoc-gen-go $GOHOME/bin/
1.2 protoc-gen-go-grpc
cd $GOPATH/src/github.com/grpc
git clone https://github.com/grpc/grpc-go.git
cd grpc-go/cmd/protoc-gen-go-grpc
go build
#生成protoc-gen-go-grpc
go install .
#or
cp protoc-gen-go-grpc $GOHOME/bin/
2. 执行proto生成grpc代码
cd grpc-go/examples/helloworld
protoc --go_out=. --go-grpc_out=. \
--go_opt=paths=source_relative \
--go-grpc_opt=paths=source_relative \
helloworld/helloworld.proto
有疑问加站长微信联系(非本文作者)