天使漫步IT工作室天使漫步IT工作室

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


Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 110

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 116

网上有很多关于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示例)

  • 开启socks5代理(比如shadowsocks)
  • 安装并启动polipo
  • 设置终端环境变量
http_proxy=127.0.0.1:1080
https_proxy=127.0.0.1:1080
  • 设置git的代理
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的语法设置目录树(也叫做报名)。

步骤:

  • 命令go env得到go的gopath的目录。如图:
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"
  • cd /Users/landsnail/go (你的目录)然后ls 查看目录
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(源文件目录)

  • mkdir golang.org/x

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

landsnail:mobile landsnail$ pwd
/Users/landsnail/go/src/golang.org/x/mobile
  • 最后执行编译命令验证是否成功,这里执行gomobile build -target=android golang.org/x/mobile/example/basic

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

完毕。

本站原创,欢迎转载,转载敬请标明出处:天使漫步IT工作室 » go get 获取项目一直timeout的两种解决办法
仅有 1 条评论
  1. 是 global 不是 globe

添加新评论


Warning: Use of undefined constant php - assumed 'php' (this will throw an Error in a future version of PHP) in /www/wwwroot/u11u.com/usr/themes/wq/comments.php on line 38