给go get设置代理解决被墙问题

起源

最近几天开始脑子发热准备学习Go 语言了,所以就准备开始写一点东西,所以就下载了GoLand 来写代码了,结果就遇到了问题。

问题

在引包的过程中出现了下载失败的问题,所以就把错误信息拿出来,查了一下,结果就是被墙了。

1
2
3
4
5
6
7
8
9
10
11
C:\Users\Vgbh>go get -v gopkg.in/fatih/pool.v2
Fetching https://gopkg.in/fatih/pool.v2?go-get=1
https fetch failed.
Fetching http://gopkg.in/fatih/pool.v2?go-get=1
import "gopkg.in/fatih/pool.v2": http/https fetch: Get http://gopkg.in/fatih/poo
l.v2?go-get=1: dial tcp 107.178.216.236:80: ConnectEx tcp: A connection attempt
failed because the connected party did not properly respond after a period of ti
me, or established connection failed because connected host has failed to respon
d.
package gopkg.in/fatih/pool.v2: unrecognized import path "gopkg.in/fatih/pool.v2
"

解决办法

解决办法就是设置http_proxy 和https_proxy 代理

1
2
3
4
5
6
7
8
9
10
11
12
13
C:\Users\Vgbh>set https_proxy=https://web-proxy.corp.xx.com:8080/

C:\Users\Vgbh>set http_proxy=https://web-proxy.corp.xx.com:8080/

C:\Users\Vgbh>go get -v gopkg.in/fatih/pool.v2
Fetching https://gopkg.in/fatih/pool.v2?go-get=1
Parsing meta tags from https://gopkg.in/fatih/pool.v2?go-get=1 (status code 200)

get "gopkg.in/fatih/pool.v2": found meta tag main.metaImport{Prefix:"gopkg.in/fa
tih/pool.v2", VCS:"git", RepoRoot:"https://gopkg.in/fatih/pool.v2"} at https://g
opkg.in/fatih/pool.v2?go-get=1
gopkg.in/fatih/pool.v2 (download)
gopkg.in/fatih/pool.v2

后边的https://web-proxy.corp.xx.com:8080/ 就是你自己本地的代理地址。

到此问题就全部解决了。