介绍
dep是一个原型依赖管理工具,需要在Go 1.7及更高的版本中使用
安装
go get -u github.com/golang/dep/cmd/dep
验证安装
$ dep
dep is a tool for managing dependencies for Go projects
Usage: dep <command>
Commands:
init Initialize a new project with manifest and lock files
status Report the status of the project's dependencies
ensure Ensure a dependency is safely vendored in the project
prune Prune the vendor tree of unused packages
Examples:
dep init set up a new project
dep ensure install the project's dependencies
dep ensure -update update the locked versions of all dependencies
dep ensure -add github.com/pkg/errors add a dependency to the project
Use "dep help [command]" for more information about a command.
常用命令
- dep init 初始化一个项目
- dep ensure 这个指令可以理解为install,根据配置下载依赖
- dep status 查看现在包缺少哪些
- dep add 添加一个包
- dep remove 移除一个包
Gopkg.html案例
# 必需包
required = ["github.com/astaxie/beego"]
# 忽略包
ignored = ["golang.org/x/crypto"]
# 项目元数据
[metadata]
homepage = "https://github.com/qiangmzsx"
license = "MIT"
owners_name_1 = "qiangmzsx"
owners_email_1 = "qiangmzsx@hotmail.com"
owners_homepage_1 = "https://github.com/qiangmzsx"
# 约束条件
[[constraint]]
name = "github.com/astaxie/beego"
# 可选:版本
version = "=1.8.0"
# 分支
#branch = "master"
# 修订
#revision = "beego 1.8.0"
# 可选:指定来源
source = "github.com/astaxie/beego"