解决go get下载包失败问题
source link: https://www.fdevops.com/2020/03/22/fix-go-get
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
由于某些不可抗力的原因,国内使用go get
命令安装包时会经常会出现timeout的问题。本文介绍几个常用的解决办法。
从github克隆
golang在github上建立了一个镜像库,如https://github.com/golang/net
就对应是 https://golang.org/x/net
的镜像库。 要下载golang.org/x/net
包,可以在本地创建包的目录后使用git clone
来拉取相应包的源代码文件,具体操作如下:
使用gopm
使用gopm可以从golang.org的一些镜像网站上下载。
安装gopm
使用gopm安装第三方包
不加-g
参数,会把依赖包下载.vendor
目录下面; 加上-g
参数,可以把依赖包下载到GOPATH
目录中。
使用goproxy
Go的1.11版本以后 可以设置GOPROXY
这个变量,来设置代理。 如果你自己有代理服务器就可以把这个环境变量设置成自己的代理。 首先开启go module
支持:
在Mac/linux下执行:
Windows平台执行:
2019.6.10更新:goproxy.cn
我们这里以https://goproxy.cn
为例:
在Mac/linux下可以执行以下命令来设置:
Windows平台在cmd
执行以下命令来设置:
或者在PowerShell
中执行:
本文为转载文章,贵在分享,版权归原作者及原出处所有,如涉及版权等问题,请及时与我联系。
原文出处:李文周的博客
原文链接:https://www.liwenzhou.com/posts/Go/fix_go_get
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK