1.govendor简介
golang工程的依赖包经常使用go get命令来获取,例如:go get github.com/kardianos/govendor ,会将依赖包下载到GOPATH
的路径下。
常用的依赖包管理工具有godep
,govendor
等,在Golang1.5之后,Go提供了 GO15VENDOREXPERIMENT
环境变量(Go 1.6版本默认开启该环境变量),用于将go build时的应用路径搜索调整成为 当前项目目录/vendor
目录方式。通过这种形式,我们可以实现类似于 godep
方式的项目依赖管理。
2.govendor安装
#v1. 0.9 wget http: //blob.wae.haplat.net/golang/govendor-v1.0.9.linux-amd64.tar.gz tar zxvf govendor-v1. 0.9 .linux-amd64.tar.gz rm /usr/bin/govendor && mv govendor /usr/bin |
3.governdor使用
初始化
#进入到项目目录 cd /path/to/your/project #初始化vendor目录 govendor init #将GOPATH中本工程使用到的依赖包自动移动到vendor目录中 #说明:如果本地GOPATH没有依赖包,先go get相应的依赖包 govendor add +external 或使用缩写: govendor add +e |
新增/更新依赖包 github拉取
# Update a package to latest, given any prior version constraint govendor fetch golang.org/x/net/context #使用HTTP协议 govendor fetch -insecure [url] # Specify a specific version or revision to fetch govendor fetch golang.org/x/net/context @a4bbce9fcae005b22ae5443f6af064d80a6f5a55 govendor fetch golang.org/x/net/context @v1 # Get latest v1.*.* tag or branch. govendor fetch golang.org/x/net/context@=v1 # Get the tag or branch named "v1" . |
更新/新增依赖包 本地GOPATH拷贝
# Update packages from $GOPATH. govendor update golang.org/x/net/context |
删除依赖包
参考