分享
golang安装使用grpc
yandaren · · 5394 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
1. 安装grpc
官网的安装命令:
go get -u google.golang.org/grpc
貌似用不了,连不上服务器,即便我挂上vpn也没有用,没办法只有迂回安装了, 反正代码在github上都有,就从github上clone下来, 需要的库包括grpc-go, golang/net, golang/text, protobuf/proto, protobuf/protoc-gen-go, google/go-genproto
# 如果已经安装了proto和protoc-gen-go的话就不用安装了
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
# 下载grpc-go
git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc
# 下载golang/net
git clone https://github.com/golang/net.git $GOPATH/src/golang.org/x/net
# 下载golang/text
git clone https://github.com/golang/text.git $GOPATH/src/golang.org/x/text
# 下载go-genproto
git clone https://github.com/google/go-genproto.git $GOPATH/src/google.golang.org/genproto
# 安装
cd $GOPATH/src/
go install google.golang.org/grpc
2. 生成grpc.pb
我们就用官网提供的helloworld example试下
protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld
plugins=grpc:helloworld, grpc:后面跟的helloworld是要生成的pb文件的文件路径
3. 运行 helloworld example
- 运行server
$ go run greeter_server/main.go - 运行client
$ go run greeter_client/main.go 2018年09月19日 11:23:31 Greeting: Hello world
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信5394 次点击
下一篇:2018年09月19日
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
1. 安装grpc
官网的安装命令:
go get -u google.golang.org/grpc
貌似用不了,连不上服务器,即便我挂上vpn也没有用,没办法只有迂回安装了, 反正代码在github上都有,就从github上clone下来, 需要的库包括grpc-go, golang/net, golang/text, protobuf/proto, protobuf/protoc-gen-go, google/go-genproto
# 如果已经安装了proto和protoc-gen-go的话就不用安装了
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
# 下载grpc-go
git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc
# 下载golang/net
git clone https://github.com/golang/net.git $GOPATH/src/golang.org/x/net
# 下载golang/text
git clone https://github.com/golang/text.git $GOPATH/src/golang.org/x/text
# 下载go-genproto
git clone https://github.com/google/go-genproto.git $GOPATH/src/google.golang.org/genproto
# 安装
cd $GOPATH/src/
go install google.golang.org/grpc
2. 生成grpc.pb
我们就用官网提供的helloworld example试下
protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld
plugins=grpc:helloworld, grpc:后面跟的helloworld是要生成的pb文件的文件路径
3. 运行 helloworld example
- 运行server
$ go run greeter_server/main.go - 运行client
$ go run greeter_client/main.go 2018年09月19日 11:23:31 Greeting: Hello world