由于墙的原因,国内使用 go get安装golang 官方包可能会失败
解决方法
方法1 [不需要FQ]
Win10下相关配置:
GOPATH : E:\go
安装记录:
E:\>go get -u -v golang.org/x/crypto/...
Fetching https://golang.org/x/crypto?go-get=1
https fetch failed: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
package golang.org/x/crypto/...: unrecognized import path "golang.org/x/crypto/..." (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
E:\>mkdir %GOPATH%\src\golang.org\x
E:\>cd %GOPATH%\src\golang.org\x
E:\go\src\golang.org\x>git clone https://github.com/golang/crypto.git
E:\go\src\golang.org\x>go install golang.org/x/crypto
can\'t load package: package golang.org/x/crypto: no Go files in E:\go\src\golang.org\x\crypto
E:\go\src\golang.org\x>go install golang.org/x/crypto/...
crypto\blake2b\blake2bAVX2_amd64.go:9:8: cannot find package "golang.org/x/sys/cpu" in any of:
C:\Go\src\golang.org\x\sys\cpu (from $GOROOT)
E:\go\src\golang.org\x\sys\cpu (from $GOPATH)
crypto\ssh\terminal\util_windows.go:22:2: cannot find package "golang.org/x/sys/windows" in any of:
C:\Go\src\golang.org\x\sys\windows (from $GOROOT)
E:\go\src\golang.org\x\sys\windows (from $GOPATH)
E:\go\src\golang.org\x>go get -u -v golang.org/x/sys
Fetching https://golang.org/x/sys?go-get=1
https fetch failed: Get
E:\go\src\golang.org\x>git clone https://github.com/golang/sys.git
E:\go\src\golang.org\x>go install golang.org/x/sys/...
E:\go\src\golang.org\x>go install golang.org/x/crypto/...
E:\go\src\golang.org\x>ls E:\go\pkg\windows_amd64\golang.org\x
crypto sys
1) 需要FQ,设置http代理
windows下:
set http_proxy=代理ip:port (临时有效)
set HTTPS_PROXY=代理ip:port (临时有效)
set ALL_PROXY=代理ip:port(临时有效)
linux下:
export http_proxy=代理ip:port (临时有效)
export HTTPS_PROXY=代理ip:port (临时有效)
或者合成一条
export ALL_PROXY=代理ip:port (临时有效)
这里使用的是shadowsock5配合cow
cow github地址
cow release地址
E:\go>ls
cow-win64-0.9.8
E:\go>cd cow-win64-0.9.8
E:\go\cow-win64-0.9.8>mv rc.txt rc.txt_bak
# 手动修改rc.txt,修改后内容如下
E:\go\cow-win64-0.9.8>cat rc.txt
listen = http://127.0.0.1:7777
proxy = socks5://127.0.0.1:1080
E:\go\cow-win64-0.9.8>cow.exe rc.txt -request -reply -v
2017/06/29 22:58:00 COW 0.9.8 listen http 127.0.0.1:7777, PAC url http://127.0.0.1:7777/pac
#打开命令一个cmd终端(curl需要自行安装,并添加入环境变量PATH中)
E:\>curl https://www.google.com
curl: (7) Failed to connect to www.google.com port 443: Timed out
# 方式1: 直接通过`-x`指定代理
E:\> curl -x http://127.0.0.1:7777 www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world\'s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you\'re looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" ht
....
# 方式2: 设置http/https代理,注意http_proxy是小写,HTTPS_PROXY是大写
E:\>set http_proxy=http://127.0.0.1:7777
E:\>set HTTPS_PROXY=http://127.0.0.1:7777
E:\> curl www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world\'s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you\'re looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" ht
....
# 此时原终端显示
E:\go\cow-win64-0.9.8>cow.exe -request -v
2017/06/29 23:17:59 COW 0.9.8 listen http 127.0.0.1:7777, PAC url http://127.0.0.1:7777/pac
[>>>>>] 2017/06/29 23:18:08 cli(127.0.0.1:5502) request CONNECT www.google.com:443
CONNECT www.google.com:443 HTTP/1.1
Host: www.google.com:443
User-Agent: curl/7.55.1
Connection: keep-alive
[>>>>>] 2017/06/29 23:18:31 cli(127.0.0.1:5544) request CONNECT www.google.com:443
CONNECT www.google.com:443 HTTP/1.1
Host: www.google.com:443
User-Agent: curl/7.55.1
Connection: keep-alive
# 说明cow http代理成功
# cow启动正常后,即可成功安装crypto
E:\>go get -u -v golang.org/x/crypto/...
Fetching https://golang.org/x/crypto?go-get=1
Parsing meta tags from https://golang.org/x/crypto?go-get=1 (status code 200)
get "golang.org/x/crypto": found meta tag get.metaImport{Prefix:"golang.org/x/crypto", VCS:"git", RepoRoot:"https://go.googlesource.com/crypto"} at https://golang.org/x/crypto?go-get=1
golang.org/x/crypto (download)
...
get "golang.org/x/sys/windows": verifying non-authoritative meta tag
golang.org/x/sys/windows
golang.org/x/crypto/ssh/terminal
# 成功安装