Go语言使用grpc

一、安装

官方安装命令: go get -u google.golang.org/grpc

由于google无法访问,虽然github上有grpc的代码,但是包依赖没有修改,所以不能go get安装,需要手动安装。

git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc

git clone https://github.com/golang/net.git $GOPATH/src/golang.org/x/net

git clone https://github.com/golang/text.git $GOPATH/src/golang.org/x/text

go get -u github.com/golang/protobuf/protoc-gen-go

git clone https://github.com/google/go-genproto.git $GOPATH/src/google.golang.org/genproto

cd $GOPATH/src/

go install google.golang.org/grpc

$GOPATH替换为环境变量的实际路径。

二、编译.proto文件

protoc --go_out=plugins=grpc:. x.proto