Golang關方依賴管理工具:dep

介紹

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 = "[email protected]"
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"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章