• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

go get golang.org/x 包失败解决方法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

由于墙的原因,国内使用 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
# 成功安装

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Go 实现判断变量是否为合法数字 IsNumeric 算法发布时间:2022-07-10
下一篇:
Windows 平台下 Go 语言的安装和环境变量设置发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap