天使漫步IT工作室

go get 获取项目一直timeout的两种解决办法

网上有很多关于go get命令timeout的解决办法,昨天试了n多最后通过反复比较终于获取成功。总结下解决办法以求能帮助更多的人。

go get golang.org/x/mobile/cmd/gomobile命令获取gomobile项目,报错信息如下:

package golang.org/x/mobile/cmd/gomobile: unrecognized import path "golang.org/x/mobile/cmd/gomobile" (https fetch: Get https://golang.org/x/mobile/cmd/gomobile?go-get=1: dial tcp 61.91.161.217:443: i/o timeout)

以上报错信息显示timeout信息,万能的搜索引擎说是被墙了。ok,那么就需要配置科学上网的办法。科学上网的办法网上很多,请自行安装。
<br/>

使用shadowsocks + polipo (mac示例)

http_proxy=127.0.0.1:1080
https_proxy=127.0.0.1:1080
git config --globle http.proxy 127.0.0.1:1080
git config --globle https.proxy 127.0.0.1:1080

mac下配置polipo

1. brew install polipo
2. vi /usr/local/opt/polipo/homebrew.mxcl.polipo.plist
3. 在<array> 和 </array>之间添加一行:
    <string>socksParentProxy=localhost:1080</string>
4. 执行命令: ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents 和
    launchctl load ~/Library/LaunchAgents/

linux下配置polipo

参考文章: shadowsocks+polipo为终端设置代理

如果配置以后再执行命令(最好重启)没有出现以上信息,则说明配置成功。但是笔者配置以后发现并没有下载成功而ping golang.org 是可以拼通,最后把git的代理配置去掉后发现成功了

分析:ping成功那么表明代理成功,但是最后出现duce to proxy timeout怀疑是git的代理没有成功,去掉后就成功了。

<br/>
有的帖子也说直接:

set http_proxy=http://127.0.0.1:1080 #这里shadowsocks的本地代理端口
set https_proxy=http://127.0.0.1:1080

也可以。

参考帖子:go get 命令得到timeout错误的解决办法(翻墙办法!)

<br/>

lantern代理

lantern也是一款优秀的翻墙利器,配置的方法参考:使用lantern解决go get 获得 golang.org 的项目

值得注意的是网上很多文章没有指出各个代理机制的端口并不同,所以需要根据自己的代理选择本地的代理端口,shadowsocks默认是1080,lantern默认的是8787(?请自行查询)

下载源码方法

如果折腾以后发现没有成功,则可以直接下载源码然后copy到go的src目录下面,请按照go的语法设置目录树(也叫做报名)。

步骤:

landsnail:~ landsnail$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/landsnail/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/15/y_vy8r992z7d1w12s5n3sbh00000gn/T/go-build303704575=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
landsnail:go landsnail$ ls -l
total 0
drwxr-xr-x  3 landsnail  staff  102  8 20 23:26 bin
drwxr-xr-x  4 landsnail  staff  136  8 20 23:34 pkg
drwxr-xr-x  4 landsnail  staff  136  8 20 23:13 src

发现bin(命令存放目录),src(源文件目录)

我这里查看到的完整路径如下:

landsnail:mobile landsnail$ pwd
/Users/landsnail/go/src/golang.org/x/mobile

如果发现gomobile build not found,则需要把gopath路径下面的bin也配置到环境变量中。即export $PATH=$PATH:$GOPATH/bin。

完毕。

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »