grpc使用指南
1、参考链接地址
grpc golang学习心得(1)----安装与测试:http://blog.csdn.net/xylin821/article/details/52335271#comments
$ protoc-gen-go: program not found or is not executable $ --go_out: protoc-gen-go: Plugin failed with status code 1.问题的解决办法:
http://qaoverflow.com/question/unable-to-build-protobuf-to-go-endpoint/?sort=oldest
http://www.th7.cn/Program/go/201604/845906.shtml
安装链接:
http://blog.csdn.net/xocoder/article/details/9155901
http://www.cnblogs.com/ghj1976/p/4564133.html
http://stackoverflow.com/questions/28099004/unable-to-build-protobuf-to-go-endpoint
http://blog.csdn.net/xylin821/article/details/52335271#comments
http://www.linuxidc.com/Linux/2016-04/129793.htm
http://www.cppblog.com/sunicdavy/archive/2014/01/21/205517.html
具体的使用步骤(针对源代码编译):
1 在网站 http://code.google.com/p/protobuf/downloads/list上可以下载 Protobuf 的源代码。然后解压编译安装便可以使用它了。
安装步骤如下所示:
1、安装编译工具
$ sudo /opt/local/bin/port install autoconf automake libtool
brew 的命令为: brew install autoconf automake libtool
否则我们就需要象下面这样,一个个的编译安装。
http://www.cainiaoer.com/2014/10/560.html
下面是我 brew 安装的截屏:
Protocol Buffers 的编译
由于我们的代码是 github 下载的, 所以我们需要先产生 配置脚本
$ ./autogen.sh
这个命令将下载gtest 源码到当前目录, 并运行 automake, autoconf 等产生配置脚本和各种模板的 makefile。
如果你使用的是 release 包, 可以跳过这一步。 下载这里,如果你无法通过命令行下载,可以手工下载后,copy到对应目录, 不过要在这个sh文件中注释掉下载那一行。
./configure --prefix=/usr/local/protobuf
make
make check
make install
安装完成后,需要确认安装的版本是 3。:
整个编译安装过程请参考:
https://github.com/google/protobuf
https://github.com/google/protobuf/blob/master/INSTALL.txt
安装 proto的 Go插件
go get -a github.com/golang/protobuf/protoc-gen-go
-a 参数标示下载好后直接做 go install
2 > sudo vim /etc/profile
添加
export PATH=$PATH:/usr/local/protobuf/bin/
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/
保存执行
source /etc/profile
同时 在~/.profile中添加上面两行代码,否则会出现登录用户找不到protoc命令
3 > 配置动态链接库路径
sudo vim /etc/ld.so.conf
插入:
/usr/local/protobuf/lib
4 > su #root 权限
ldconfig
5>安装sudo apt-get install golang-goprotobuf-dev
6>使用插件生成pb的文件
protoc --plugin=protoc-gen-go=$GOPATH/bin/protoc-gen-go --go_out=plugins=grpc:. *.proto
注意:
Windows下protoc-gen-go的使用方法(goprotobuf)
goprotobuf是go语言中写的较好的一个实现, linux下的安装非常方便, 但是windows需要添加plugin的路径才能识别
先确认你已经设置好GOPATH, 并安装好goprotobuf
我的goprotobuf路径是标准的: $GOPATH/src/code.google.com/p/goprotobuf
编译并安装proto工具:
go install code.google.com/p/goprotobuf/proto
go install code.google.com/p/goprotobuf/protoc-gen-go
确认$GOPATH/bin下有protoc-gen-go.exe
编译proto文件输出go文件:
使用命令行编译path/to/protoc.exe --plugin=protoc-gen-go=$GOPATHinprotoc-gen-go.exe --go_out . --proto_path . XXX.proto
这里顺便贴出notepad++使用nppexec插件的command