原文链接:/articles/20364
go作为Google大佬的亲儿子,go开发过程中除了SDK自带的包外还经常会需要用到大佬提供的其他包,这些包都在下,而下载这些包需要访问大佬的服务器,国内开发者就会遇到各种墙的问题,今天就给大家总结一下有哪些途径安装这些包.
1. VPN
如果有条件的,公司能够提供稳定可靠的vpn,建议使用VPN,当然也有一些免费的vpn,实测效果很不好
2. gopm
gopm是一个开源的GoPackage Manager的管理工具,在go mod之前比较好使,github地址:/gpmgo/gopm
使用思路:
1. 安装gopm
go get -u /gpmgo/gopmgo install gopm
2. 使用gopm安装包
gopm get /x/net
实测这个效果在1.11版本后不好使
3. install form github
思路: Google大佬知道很多开发者因为环境限制不能访问的包,所以这些包在github上都有Copy,但是只是Copy,其中的包依赖还是,所以目前不能像gopm那样一键全部安装,但是实测可用,接下来以grpc为例,说明如果解决go package 依赖问题.
1. 当前环境
执行go env,主要看两个参数, GOPATH和GOROOT
D:\GoProject>go env
set GOPATH=D:\GoProject
set GOROOT=D:\Go
我的GOPATH目录的src目录如下:
2. 无VPN安装GRPC
grpc的quickstart地址:https://grpc.io/docs/quickstart/go.html
新开一个terminal,执行
go get -u /grpc
D:\GoProject>go get -u /grpcpackage /grpc: unrecognized import path "/grpc" (https fetch: Get /grpc?go-get=1: ddial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of tim dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)package /grpc: unrecognized import path "/grpc" (https fetch: Get /grpc?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond aftera period of time, or established connection failed because connected host has failed to respond.)
很明显,直接提示网络不通
3. 下载grpc-go源码
D:\GoProject\src>git clone /grpc/grpc-go .//grpcCloning into './/grpc'...remote: Enumerating objects: 7, done.remote: Counting objects: 100% (7/7), done.remote: Compressing objects: 100% (7/7), done.remote: Total 14988 (delta 1), reused 1 (delta 0), pack-reused 14981Receiving objects: 100% (14988/14988), 7.38 MiB | 344.00 KiB/s, done.Resolving deltas: 100% (9466/9466), done.
4. go install grpc
D:\GoProject\src>go install /\grpc\internal\transport\controlbuf.go:27:2: cannot find package "/x/net/http2" in any of:D:\Go\src\\x\net\http2 (from $GOROOT)D:\GoProject\src\\x\net\http2 (from $GOPATH)\grpc\internal\transport\controlbuf.go:28:2: cannot find package "/x/net/http2/hpack" in any of:D:\Go\src\\x\net\http2\hpack (from $GOROOT)D:\GoProject\src\\x\net\http2\hpack (from $GOPATH)\grpc\server.go:36:2: cannot find package "/x/net/trace" in any of:D:\Go\src\\x\net\trace (from $GOROOT)D:\GoProject\src\\x\net\trace (from $GOPATH)\grpc\status\status.go:37:2: cannot find package "/genproto/googleapis/rpc/status" in any of:D:\Go\src\\genproto\googleapis\rpc\status (from $GOROOT)D:\GoProject\src\\genproto\googleapis\rpc\status (from $GOPATH)
提示缺少/x/net 和/genproto这两个包
5. 安装/x/net包和genproto包
在github中找到go组织,搜索到net包如下
D:\GoProject\src>git clone /golang/net.git .//x/netCloning into './/x/net'...remote: Enumerating objects: 13, done.remote: Counting objects: 100% (13/13), done.remote: Compressing objects: 100% (8/8), done.remote: Total 8291 (delta 5), reused 10 (delta 5), pack-reused 8278Receiving objects: 100% (8291/8291), 6.47 MiB | 448.00 KiB/s, done.Resolving deltas: 100% (5758/5758), done.
D:\GoProject\src>git clone /google/go-genproto.git .//genprotoCloning into './/genproto'...remote: Enumerating objects: 1474, done.remote: Counting objects: 100% (1474/1474), done.remote: Compressing objects: 100% (763/763), done.remote: Total 11217 (delta 611), reused 1474 (delta 611), pack-reused 9743Receiving objects: 100% (11217/11217), 15.98 MiB | 451.00 KiB/s, done.Resolving deltas: 100% (5695/5695), done.Checking out files: 100% (1268/1268), done.
6. go install grpc
D:\GoProject\src>go install /\x\net\idna\idna.go:23:2: cannot find package "/x/text/secure/bidirule" in any of:D:\Go\src\\x\text\secure\bidirule (from $GOROOT)D:\GoProject\src\\x\text\secure\bidirule (from $GOPATH)\x\net\idna\idna.go:24:2: cannot find package "/x/text/unicode/bidi" in any of:D:\Go\src\\x\text\unicode\bidi (from $GOROOT)D:\GoProject\src\\x\text\unicode\bidi (from $GOPATH)\x\net\idna\idna.go:25:2: cannot find package "/x/text/unicode/norm" in any of:D:\Go\src\\x\text\unicode\norm (from $GOROOT)D:\GoProject\src\\x\text\unicode\norm (from $GOPATH)
我们发现又缺少text包,go on...
D:\GoProject\src>git clone /golang/text.git .//x/textCloning into './/x/text'...remote: Enumerating objects: 32, done.remote: Counting objects: 100% (32/32), done.remote: Compressing objects: 100% (20/20), done.remote: Total 5612 (delta 11), reused 32 (delta 11), pack-reused 5580Receiving objects: 100% (5612/5612), 19.67 MiB | 442.00 KiB/s, done.Resolving deltas: 100% (3732/3732), done.D:\GoProject\src>go install /grpcD:\GoProject\src>
7. 测试安装
基本上go install没有提示错误,grpc就算安装好了,我们现在拿grpc里的example来测试下
// 先启动serverD:\GoProject\src>go run /grpc/examples/helloworld/greeter_server/main.go/03/13 10:50:11 Received: world//后启动clientD:\GoProject\src>go run /grpc/examples/helloworld/greeter_client/main.go/03/13 10:50:11 Greeting: Hello world
如果觉得《go get国内解决办法汇总》对你有帮助,请点赞、收藏,并留下你的观点哦!