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还在官方试验阶段,但已表示生产可安全使用

Go依赖管理工具 - dep的更多相关文章

  1. Go 包依赖管理工具 —— govendor

    govendor 是一个基于 vendor 机制实现的 Go 包依赖管理命令行工具.与原生 vendor 无侵入性融合,也支持从其他依赖管理工具迁移,可以很方便的实现同一个包在不同项目中不同版本.以及 ...

  2. Go包管理工具dep

    dep是一个golang依赖管理工具,需要在Go 1.7及更高的版本中使用. 1. 安装 安装dep工具的方式有很多种,如果是mac电脑的话,只需要如下命令: brew install dep 对于L ...

  3. Composer : php依赖管理工具

    原始时代 我记得在当时用php的时候还没有composer,只有个pear,但是不好用呀,还不如直接在互联网上到处复制代码了,更快更不容易出错,当时也没有github这么好的社区工具了 总结如下 代码 ...

  4. composer php依赖管理工具

    #composer是什么 Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. composer出现之前我们php项目依赖管理大部分都是手动 ...

  5. yarn依赖管理工具的使用

    Yarn是Facebook发布的一款依赖管理工具,它比npm更快.更高效. 与NPM命令对照 npm install => yarn install npm install --save [pa ...

  6. Golang依赖管理工具:glide从入门到精通使用

    这是一个创建于 2017-07-22 05:33:09 的文章,其中的信息可能已经有所发展或是发生改变. 介绍 不论是开发Java还是你正在学习的Golang,都会遇到依赖管理问题.Java有牛逼轰轰 ...

  7. PHP的依赖管理工具----composer

    安装Composer 参考:https://getcomposer.org/doc/01-basic-usage.md composer 是PHP依赖管理工具 PHP最低版本要求5.3.2,需要允许o ...

  8. 有用PHP依赖管理工具Composer新手教程

    PHP依赖管理工具Composer新手教程 Composer 是 PHP 的一个依赖管理工具.它同意你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 依赖管理 Composer 不是一个包管理 ...

  9. golang多个项目时如何配置GOPATH,使用gb包依赖管理工具,不同项目配置不同的GOPATH的

    golang多个项目时如何配置GOPATH,使用gb包依赖管理工具,不同项目配置不同的GOPATH的 1:执行脚本setGoPath.sh#!/bin/bashif [[ $GOPATH =~ .*$ ...

随机推荐

  1. Intellij IDEA运行前不检查其他类的错误

    解决方法 第一步 第二步 在工具栏选择 , Run Configurations  设置在运行前不检查错误 

  2. 小白的C++之路——求质数

    初学C++,打算用博客记录学习的足迹.写了两个求质数的程序,修修改改. #include <iostream> #include <math.h> using namespac ...

  3. 安装Windows10出现无法识别磁盘时的解决方案

    由于前些日子对deepin系统比较感兴趣,一时兴起把备用机刷成了deepin,奈何还是过分依赖windows下的软件,又不得不再刷回Win10. 但由于Linux支持的磁盘格式与Windows不同,在 ...

  4. Java笔记_静态变量和实例变量的区别

    这里简单做一下笔记,区分Java全局变量里的静态变量与实例变量. 1.Java里的全局变量 首先了解Java里的全局变量,也叫成员变量. 特点: (1).一个类中既不在方法体内,也不在程序块内定义的变 ...

  5. Lua代码编写规范

    开发中,大量使用lua,暂时根据当前状况,总结相对而言较好的规范,在多人协作中可以更好的开发.交流. 介绍  该文档旨在为使用lua编写应用程序建立编码指南. 制订编码规范的目的: 统一编码标准,通用 ...

  6. [Atcoder AGC032C]Three Circuits

    题目大意:有一张$n$个点$m$条边的无向连通图,判断是否可以从中分出$3$个环,满足三个环覆盖整张图并且没有重复的边.$n,m\leqslant10^5$ 题解:分类讨论.有度数为奇肯定不行,因为连 ...

  7. mingw 编译 glfw3 的 helloworld

    glfw3 为基础开发 GUI 似乎是一个不错选项,有很多人尝试这么做了.今天也小试一把. 工具: mingw(不是 mingw-w64),头文件 GLFW/ ,库文件 glfw3.dll 需要注意, ...

  8. Html中Css页面跳转问题

    没有指定<a>的target属性值时,默认是"_blank,可以参考以下代码的设置来控制<a href="#" target="_blank& ...

  9. js 对象克隆方法总结(不改变原对象)

    1.通用对象克隆: function clone(obj){ let temp = null; if(obj instanceof Array){ temp = obj.concat(); }else ...

  10. mysql 获取指定日期到指定日期 区间段的日期

    第一种方法: cross join (就相当于mysql中的循环) CROSS JOIN 把两张表中的数据进行 N * M的组合,即笛卡尔积 这里的两张表利用 union all都有5条数据,所以进行 ...