Posts Golang 依赖包下载时候代理设置
Post
Cancel

Golang 依赖包下载时候代理设置

我们在使用 Go 下载依赖时候经常遇到网络环境的问题,如:golang.org 站点必须要翻墙才可以进行下载;而单单设置系统层面的 http_proxy 有时也不能完全解决问题,所以我记录了我尝试过的解决方案 - 必须要设置两种代理方式才行(仓库代理与系统代理),具体参考下面的使用。

切记两种代理必须要同时设置才可起作用;吐槽一下:这种方式好蛋疼。

仓库代理

Git

1
git config [--global] http.proxy http://proxy.example.com:port

Mercurial

编辑 ~/.hgrc 文件并加入以下内容:

1
2
[http_proxy]
host=proxy.example.com:port

SVN

编辑 ~/.subversion/servers 文件并加入以下内容:

1
2
3
[Global]
http-proxy-host=proxy.example.com
http-proxy-port=xxxx

系统代理

局部

参考下面命令,这个设置只是一次性的。

1
http_proxy=http://127.0.0.1:1087 go get -u -v github.com/golang/lint/golint

全局

~/.bash_profile 文件并加入以下内容:

1
export http_proxy=proxy.example.com:port

错误信息

  • fatal: unable to access ‘https://go.googlesource.com/tools/’: Failed to connect to go.googlesource.com port 443: Operation timed out
  • https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
  • unrecognized import path “golang.org/x/tools/go/buildutil” (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

参考地址

https://github.com/golang/go/wiki/GoGetProxyConfig https://github.com/Microsoft/vscode-go/issues/653

This post is licensed under CC BY 4.0

Docker 发展及核心理论

Javascript HTML5 Canvas 时钟绘制

Comments powered by Disqus.