(一)govender的功能
govender 是对Golang的包依赖管理的一个插件,该工具将项目依赖的外部包拷贝到项目下的 vendor 目录下,并通过 vendor.json 文件来记录依赖包的版本,方便用户使用相对稳定的依赖。
govender的几种状态。
状态 | 缩写 | 含义 |
---|---|---|
+local | l | 本地包,即项目自身的包组织 |
+external | e | 外部包, 被GOPATH管理 |
+vender | v | 被govender 管理 |
+std | s | 标准库 |
+unused | u | 未使用的包 |
+missing | m | 代码引用了依赖包,但是该包找到 |
+program | p | 主程序包,意味着可以编译为执行文件 |
+outside | 外部包和缺失的包 | |
+all | 所有包 |
(二)govender 的基本使用
下载
go get -u github.com/kardianos/govendor
运行govender,出现以下结果说明安装成功
govendor (v1.0.9): record dependencies and copy into vendor folder
-govendor-licenses Show govendor's licenses.
-version Show govendor version
-cpuprofile 'file' Writes a CPU profile to 'file' for debugging.
-memprofile 'file' Writes a heap profile to 'file' for debugging.
简单的使用
# Setup your project.
cd "my project in GOPATH"
# 初始化 vendor 目录, project 下出现 vendor 目录
govendor init
# Add existing GOPATH files to vendor.
govendor add +external
# View your work.
govendor list
# Look at what is using a package
govendor list -v fmt
# Specify a specific version or revision to fetch
govendor fetch golang.org/x/net/context@a4bbce9fcae005b22ae5443f6af064d80a6f5a55
# Get latest v1.*.* tag or branch.
govendor fetch golang.org/x/net/context@v1
# Get the tag or branch named "v1".
govendor fetch golang.org/x/net/context@=v1
# Update a package to latest, given any prior version constraint
govendor fetch golang.org/x/net/context
# Format your repository only
govendor fmt +local
# Build everything in your repository only
govendor install +local
# Test your repository only
govendor test +local
一些基本命令
init 创建 vendor 文件夹和 vendor.json 文件
list 列出已经存在的依赖包
add 从 $GOPATH 中添加依赖包,会加到 vendor.json
update 从 $GOPATH 升级依赖包
remove 从 vendor 文件夹删除依赖
status 列出本地丢失的、过期的和修改的package
fetch 从远端库增加新的,或者更新 vendor 文件中的依赖包
sync Pull packages into vendor folder from remote repository with revisions
migrate Move packages from a legacy tool to the vendor folder with metadata.
get 类似 go get,但是会把依赖包拷贝到 vendor 目录
license List discovered licenses for the given status or import paths.
shell Run a "shell" to make multiple sub-commands more efficient for large projects.
go tool commands that are wrapped:
`+<status>` package selection may be used with them
fmt, build, install, clean, test, vet, generate, to
有疑问加站长微信联系(非本文作者)