美文网首页技术文档
mac osx grpc-go 开发环境搭建

mac osx grpc-go 开发环境搭建

作者: 奶爸撸代码 | 来源:发表于2018-12-02 23:52 被阅读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
  • 以上是基于release版本变异安装的过程。如果直接git clone master分支,可能还需要先安装xcode,之后:
    sudo xcode-select --install
  • 更详细步骤参考github项目protobuf

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使用笔记,下篇计划:

  • grpc-go使用入门级示例。

相关文章

网友评论

    本文标题:mac osx grpc-go 开发环境搭建

    本文链接:https://www.haomeiwen.com/subject/wwascqtx.html