glide是golang的一款包管理工具,就像Java下的Maven(当然Maven的定位不只是包管理工具)。今天试用了一下,记录一下使用过程和遇到的一些坑。
环境
Windows 7,Goland,Go 1.8.4
安装
go get -u github.com/Masterminds/glide
在Goland中打开File——Settings——Tools——External Tools,根据自己的gopath添加gopath\bin\glide.exe,如图
在Goland中输入命令:
glide
如果出现提示就证明安装成功了。
使用
不多说,直接上命令:
glide init
然后就会生成对应的glide.yaml,生成过程中根据自己需要选择合适的配置就行。
我的glide.yaml如下:
package: github.com/AceDarkkinght/GoProxyCollector
import:
- package: github.com/PuerkitoBio/goquery
version: ~1.3.0
- package: github.com/boltdb/bolt
version: ~1.3.1
- package: github.com/cihub/seelog
version: ~2.6.0
- package: github.com/parnurzeal/gorequest
version: ~0.2.15
现在就可以通过命令下载对应的dependencies了
glide install
然后就毫无意外的出错了。。。。
[WARN] Unable to set version on golang.org/x/net/html to . Err: Cannot detect VCS
[ERROR] Error scanning golang.org\x\net\html: open C:\Users\yourUserName\.glide\cache\src\https-golang.org-x-net-html: The system cannot find the file specif
ied.
[ERROR] Failed to retrieve a list of dependencies: Error resolving imports
这是由于墙的原因导致有些google的包下不下来,我们可以使用mirror命令指定镜像,从镜像地址下载。命令如下:
glide mirror set https://golang.org/x/net/html https://github.com/golang/net --vcs git
glide mirror set https://golang.org/x/net/publicsuffix https://github.com/golang/net --vcs git
glide mirror set https://golang.org/x/sys/unix https://github.com/golang/sys --vcs git
再次运行:
glide install
再出错:
[ERROR] Unable to export dependencies to vendor directory: Error moving files: exit status 1. output: Access is denied. 0 dir(s) moved.
查了资料发现这是Windows下和文件权限有关的一个bug,github上面有相关讨论:
https://github.com/Masterminds/glide/issues/873
网友给出了两个解决方案:
这里采用第一种方法:
// 找到github.com/Masterminds/glide/path/winbug.go
// 修改 func CustomRename(o, n string) error
// 把 cmd := exec.Command("cmd.exe", "/c", "move", o, n) 改为
cmd := exec.Command("robocopy.exe", o, n, "/e")
保存修改,重新编译。
go get -u github.com/Masterminds/glide
然后运行:
glide install
如无意外的话你就可以在项目路径看到vendor文件夹了。
如果你有更好的办法或者遇到了别的问题也欢迎一起讨论。
Reference
https://studygolang.com/articles/7129
https://github.com/Masterminds/glide/issues/873
https://my.oschina.net/quicker/blog/831352?hmsr=studygolang.com&utm_medium=studygolang.com&utm_source=studygolang.com
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com