62

如何导入golang.org的包

 5 years ago
source link: https://segmentfault.com/a/1190000018220783?amp%3Butm_medium=referral
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.

golang是google开源的编程语言,用久了就会对这个事实有深刻的体会

比如说,go get一些包的时候,失败liao。

zIFjiqV.png!web

怎么解决国内golang.org下的包无法下载到本地GOPATH的问题呢?

例子: github.com/colinmarc/hdfs 这个包用到了golang.org/x/crypto的部分功能

  • 原因:golang.org解析出来是google的ip,“理所应当”被拒绝访问
  • 办法,找到github的镜像包:

Ini6RzM.png!web

  • 步骤:git clone [镜像地址].然后在第一个GOPATH下依次新建文件夹golang.org,x(golang.org文件夹应该跟github.com文件夹同级)。然后把下载的crypto文件夹复制过来。
  • 最后:go get github.com/colinmarc/hdfs导入的包就可以正常调用了。根据自己的实际情况导入响应的包,步骤基本类似,关键在于找到你要的镜像。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK