技术文档

mac osx grpc-go 开发环境搭建

2018-12-02  本文已影响67人  奶爸撸代码

0. 先决必要条件:golang 1.9+,这里略过。

1. quick install

来自这里 https://github.com/grpc/homebrew-grpc

brew tap grpc/grpc
brew install --with-plugins grpc

2. 从代码编译安装

2.1 protobuf install

brew install autoconf automake libtool curl make g++ unzip
下载[protobuf](https://github.com/protocolbuffers/protobuf/releases/latest)
tar -zxvf protobuf-x.x.x
cd protobuf-x.x.x
./configure --prefix=/usr
make
make check
sudo make install
protoc --version

2.2 grpc-go install

官方安装命令:go get google.golang.org/grpc
然而一般都会失败报错:

https fetch failed: Get https://google.golang.org/grpc?go-get=1: net/http: TLS handshake timeout

原因你懂的。
其实是这个代码已经转移到github上面了,但是代码里面的包依赖还是没有修改,还是google.golang.org这种,
所以:


    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 -v github.com/golang/protobuf/{proto,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

3. 总结

至此,grpc-go mac 开发环境ready!后续将继续分享grpc使用笔记,下篇计划:

上一篇下一篇

猜你喜欢

热点阅读