1. dep简介

dep是一个golang项目的包管理工具,一般只需要2-3个命令就可以将go依赖包自动下载并归档到vendor的目录中。dep官网参考:https://github.com/golang/dep

2. dep安装

  1. go get -u github.com/golang/dep/cmd/dep

3. dep使用

  1. #进入到项目目录
  2. cd /home/gopath/src/demo
  3. #dep初始化,初始化配置文件Gopkg.toml
  4. dep init
  5. #dep加载依赖包,自动归档到vendor目录
  6. dep ensure
  7. # 最终会生成vendor目录,Gopkg.toml和Gopkg.lock的文件

4. dep的配置文件

Gopkg.toml记录依赖包列表。

  1. # Gopkg.toml example
  2. #
  3. # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
  4. # for detailed Gopkg.toml documentation.
  5. #
  6. # required = ["github.com/user/thing/cmd/thing"]
  7. # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
  8. #
  9. # [[constraint]]
  10. # name = "github.com/user/project"
  11. # version = "1.0.0"
  12. #
  13. # [[constraint]]
  14. # name = "github.com/user/project2"
  15. # branch = "dev"
  16. # source = "github.com/myfork/project2"
  17. #
  18. # [[override]]
  19. # name = "github.com/x/y"
  20. # version = "2.4.0"
  21. #
  22. # [prune]
  23. # non-go = false
  24. # go-tests = true
  25. # unused-packages = true
  26. ignored = ["demo"]
  27. [[constraint]]
  28. name = "github.com/BurntSushi/toml"
  29. version = "0.3.0"
  30. [prune]
  31. go-tests = true
  32. unused-packages = true

5. dep-help

更多dep的命令帮助参考dep

  1. $ dep
  2. Dep is a tool for managing dependencies for Go projects
  3. Usage: "dep [command]"
  4. Commands:
  5. init Set up a new Go project, or migrate an existing one
  6. status Report the status of the project's dependencies
  7. ensure Ensure a dependency is safely vendored in the project
  8. prune Pruning is now performed automatically by dep ensure.
  9. version Show the dep version information
  10. Examples:
  11. dep init set up a new project
  12. dep ensure install the project's dependencies
  13. dep ensure -update update the locked versions of all dependencies
  14. dep ensure -add github.com/pkg/errors add a dependency to the project
  15. Use "dep help [command]" for more information about a command.