https://segmentfault.com/a/1190000013561841

Go依赖管理工具

Go dependency management tool

环境要求

  • Golang >= 1.9
  • Dep

目前版本:

dep:
version : devel
build date :
git hash :
go version : go1.10
go compiler : gc
platform : linux/amd64

Latest releasev0.4.1

安装

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

$GOPATH/bin不在PATH下,则需要将生成的dep文件从$GOPATH/bin移动至$GOBIAN

验证

$ dep
Dep is a tool for managing dependencies for Go projects Usage: "dep [command]" Commands: init Set up a new Go project, or migrate an existing one
status Report the status of the project's dependencies
ensure Ensure a dependency is safely vendored in the project
prune Pruning is now performed automatically by dep ensure.
version Show the dep version information 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在初始化时会分析应用程序所需要的所有依赖包,得出依赖包清单

并生成vendor目录,Gopkg.tomlGopkg.lock文件

默认初始化

$ dep init -v

直接从对应网络资源处下载

优先从$GOPATH初始化

$ dep init -gopath -v

该命令会先从$GOPATH查找既有的依赖包,若不存在则从对应网络资源处下载

Gopkg.toml

该文件由dep init生成,包含管理dep行为的规则声明

required = ["github.com/user/thing/cmd/thing"]

ignored = [
"github.com/user/project/pkgX",
"bitbucket.org/user/project/pkgA/pkgY"
] [metadata]
key1 = "value that convey data to other systems"
system1-data = "value that is used by a system"
system2-data = "value that is used by another system" [[constraint]]
# Required: the root import path of the project being constrained.
name = "github.com/user/project"
# Recommended: the version constraint to enforce for the project.
# Note that only one of "branch", "version" or "revision" can be specified.
version = "1.0.0"
branch = "master"
revision = "abc123" # Optional: an alternate location (URL or import path) for the project's source.
source = "https://github.com/myfork/package.git" # Optional: metadata about the constraint or override that could be used by other independent systems
[metadata]
key1 = "value that convey data to other systems"
system1-data = "value that is used by a system"
system2-data = "value that is used by another system"

Gopkg.lock

该文件由dep ensuredep init生成,包含一个项目依赖关系图的传递完整快照,表示为一系列[[project]]

# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.

[[projects]]
branch = "master"
name = "github.com/golang/protobuf"
packages = [
"jsonpb",
"proto",
"protoc-gen-go/descriptor",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/struct",
"ptypes/timestamp"
]
revision = "bbd03ef6da3a115852eaf24c8a1c46aeb39aa175"

常用命令

dep ensure

从项目中的Gopkg.tomlGopkg.lock中分析关系图,并获取所需的依赖包

用于确保本地的关系图、锁、依赖包清单完全一致

dep ensure -add

# 引入该依赖包的最新版本
dep ensure -add github.com/pkg/foo # 引入具有特定约束(指定版本)的依赖包
dep ensure -add github.com/pkg/foo@^1.0.1

dep ensure -update

Gopkg.lock中的约定依赖项更新为Gopkg.toml允许的最新版本

最后

目前dep还在官方试验阶段,但已表示生产可安全使用

最新文章

  1. 长年承接AR图像识别项目,关于高速UnityARCam多图问题技术整理
  2. 【leetcode】Validate Binary Search Tree
  3. 在Javascript中监听flash事件(转)
  4. Excel操作--使用NPOI导入导出Excel为DataTable
  5. Javascript学习之函数(function)
  6. Swift与Objective-C交互
  7. scala Actor Akka
  8. java(8)二重循环
  9. 基于VC的MFC界面开发
  10. ESLint具体规则设置
  11. cdn帮助链接汇集
  12. JAVA对象 向上转型upcasting,向下转型downcasting
  13. C# Params的使用
  14. kali系统固化到固态硬盘小记(赠送给广大折腾党的笔记)
  15. 为springboot项目添加springboot-admin监控
  16. Codeforces 219C - Color Stripe - [DP]
  17. myeclipse 10配置jboss 7.1.1无法启动Error: Could not create the Java Virtual Machine
  18. Nodejs学习笔记(四)与MySQL交互(felixge/node-mysql)
  19. Rust笔记
  20. Python中常见的数据类型总结

热门文章

  1. C语言字节对齐分析
  2. ubuntu 17.04 下搭建深度学习环境
  3. Golang检测Linux服务器端口占用
  4. FusionInsight大数据开发---HDFS应用开发
  5. Java学习:内部类的概念于分类
  6. 独立使用 ecj
  7. 安装软件时出现这样错误:文件“proe50-1a.bin”无法在“C:\User\ZFTL\Desktop\proe50”定位,请插入正确的磁盘或选择其他文件夹
  8. SQL Server中临时表是在什么schema下的(转载)
  9. 前端不缓存,ajax不缓存,js操作cookie
  10. 一张图看懂SharpSocket