Golang安装gRPC

官方安装命令:

go get google.golang.org/grpc

但是这样安装是装不上的

package google.golang.org/grpc: unrecognized import path "google.golang.org/grpc"(https fetch: Get https://google.golang.org/grp...: dial tcp 216.239.37.1:443: i/o timeout)

由于国内的网络原因,并且代码已经转移到github上面了,但是代码里面的包依赖还是没有修改,还是google.golang.org这种,所以不能使用go get的方式安装(当然翻墙之后就可以了)。
因此我们介绍不需要翻墙的安装方法:

在 GOPATH 下创建 google.golang.org 目录

mkdir -p $GOPATH/src/google.golang.org/
cd $GOPATH/src/google.golang.org/

拉取源代码

git clone https://github.com/grpc/grpc-go grpc

这时我们去执行安装命令

go install google.golang.org/grpc

会提示丢失了一些安装包,类似:

grpc/internal/transport/controlbuf.go:27:2: cannot find package "golang.org/x/net/http2" in any of:
/home/dc2-user/go/src/golang.org/x/net/http2 (from $GOROOT)
/home/dc2-user/gopath/src/golang.org/x/net/http2 (from $GOPATH)
grpc/internal/transport/controlbuf.go:28:2: cannot find package "golang.org/x/net/http2/hpack" in any of:
/home/dc2-user/go/src/golang.org/x/net/http2/hpack (from $GOROOT)
/home/dc2-user/gopath/src/golang.org/x/net/http2/hpack (from $GOPATH)

根据提示去安装对应的包即可。

安装 golang.org/x/*(安装对应的即可)

git clone https://github.com/golang/sys.git 
git clone https://github.com/golang/net.git 
git clone https://github.com/golang/text.git 
git clone https://github.com/golang/lint.git 
git clone https://github.com/golang/tools.git 
git clone https://github.com/golang/crypto.git

相关推荐