安装grpc 简述

来源:互联网 发布:实况2017数据 编辑:程序博客网 时间:2024/06/07 05:36
一、grpc安装前,先安装protobuf
1,下载源码
git clonehttps://github.com/google/protobuf.git
2,编译前,安装工具
brew install autoconf automake libtool curl unzip
3, 编译
./autogen.sh
./configure
make
sudo make install

二、安装grpc
1, 能访问外网,直接安装
go get google.golang.org/grpc
2, 不能访问外网,下载源码安装
git clonehttps://github.com/grpc/grpc.git

三、protoc插件安装
没这个,无法通过proto生成代码
brew install --with-plugins grpc

四、生成代码示例
1,golang代码
protoc --go_out=plugins=grpc:. helloworld.proto
2,C++代码
服务端:protoc --grpc_out=./ --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` helloworld/helloworld.proto
客户端:protoc --cpp_out=. ./helloworld/helloworld.proto