内容简介:安装:初始化:下面介绍三个命令:
安装:
go get -u -v github.com/kardianos/govendor 复制代码
初始化:
# Setup your project. cd "my project in GOPATH" govendor init # Add existing GOPATH files to vendor. govendor add +external 复制代码
下载依赖包
下面介绍三个命令:
govendor fetch govendor get govendor add
综上,如果是下载依赖包,一定是用 govendor fetch
。
govendor fetch github.com/gin-gonic/gin@v1.2 # 只拷贝 gin/ 目录的内容,而不包含其子目录 govendor fetch github.com/gin-gonic/gin/...@v1.2 # 可以得到 gin/ 目录,及其所有子目录 复制代码
@v1.2
表示使用 v1.2 版本,其实就是 git tag 为 v1.2 的 revision,这个功能很实用。
再说一个可能会碰到的问题,有时候我们使用第三方依赖包,而且还有 bug,修复之后,期望使用自己仓库的时候,可以这样做:
govendor get 'github.com/go-sql-driver/mysql::github.com/yongxinz/go-mysql' 复制代码
原仓库的 github.com/go-sql-driver/mysql
存在一个小问题,此时期望使用自己修复过的 github.com/yongxinz/go-mysql
。
版本管理
不要将整个 vendor/
目录的内容都提到 git 仓库,只提交 vendor/vendor.json
文件就可以了。
当我们拉代码之后,需要安装依赖包时,只需要执行下面这条命令就可以了。
govendor sync 复制代码
.gitignore
文件,重点在最后两行:
# Created by https://www.gitignore.io/api/go ### Go ### # Binaries for programs and plugins *.exe *.exe~ *.dll *.so *.dylib # Test binary, build with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out ### Go Patch ### /vendor/ !/vendor/vendor.json 复制代码
所以,一般的开发流程可以这样来做:如果是新建项目,先安装 govendor 并初始化,然后通过 govendor 来安装依赖包;如果是已有项目,先从版本库拉下来,然后安装 govendor,再执行同步命令即可。
其他命令
govendor status
: 查看当前包状态
govendor list +e
: 查看当前项目的依赖但是未被添加到 vendor
中的包
govendor add +e
: 添加依赖的包。如果 vendor.json
中存在,但是 vendor
目录下不存在(即 govendor status
显示缺失)的包也会被重新添加
govendor remove +u
: 删除在 vendor
下但是未依赖的包
在实际过程中,有部分包是团队的公共包。 这部分包通常有自己的单独项目,并且已经被我们添加到 $GOPATH
下,可能就不需要添加到当前项目的 vendor
下。
这时候可以结合 list
和 add
来使用, 先用 list -no-status +e
列出依赖包,然后使用 grep
过滤,再调用 add
命令添加:
govendor list -no-status +e | grep -v 'myteam/common' | xargs govendor add 复制代码
以上所述就是小编给大家介绍的《Go 包管理工具 govendor 使用指南》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Learning JavaScript
Shelley Powers / Oreilly & Associates Inc / 2006-10-17 / $29.99
As web browsers have become more capable and standards compliant, JavaScript has grown in prominence. JavaScript lets designers add sparkle and life to web pages, while more complex JavaScript has led......一起来看看 《Learning JavaScript》 这本书的介绍吧!