由于国内的网络环境导致在下载依赖 golang.org/x
下的包时一般会出错。
比如 :
一般你可以通过设置代理,如果代理使用了 pac 模式的话,可能需要编辑下 pac 文件。下面要介绍的是一种不代理的解决办法。
原理
-
当我们使用
import "golang.org/x/tools/go/buildutil"
导入包时,其实导入的是$GOPATH/src/golang.org/x/tools/go/buildutil
目录的包。
实例
比如先切换到 $GOPATH
的 src 目录,cd $GOPATH/src
,然后按需要下载:
git clone --depth 1 golang.org/x/tools
git clone --depth 1 golang.org/x/lint
git clone --depth 1 golang.org/x/net
git clone --depth 1 golang.org/x/sys
git clone --depth 1 golang.org/x/crypto
git clone --depth 1 golang.org/x/text
git clone --depth 1 golang.org/x/image
git clone --depth 1 golang.org/x/oauth2