Go依赖管理工具 - dep
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 release
为v0.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.toml
、Gopkg.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 ensure
和dep 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.toml
和Gopkg.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的更多相关文章
- Go 包依赖管理工具 —— govendor
govendor 是一个基于 vendor 机制实现的 Go 包依赖管理命令行工具.与原生 vendor 无侵入性融合,也支持从其他依赖管理工具迁移,可以很方便的实现同一个包在不同项目中不同版本.以及 ...
- Go包管理工具dep
dep是一个golang依赖管理工具,需要在Go 1.7及更高的版本中使用. 1. 安装 安装dep工具的方式有很多种,如果是mac电脑的话,只需要如下命令: brew install dep 对于L ...
- Composer : php依赖管理工具
原始时代 我记得在当时用php的时候还没有composer,只有个pear,但是不好用呀,还不如直接在互联网上到处复制代码了,更快更不容易出错,当时也没有github这么好的社区工具了 总结如下 代码 ...
- composer php依赖管理工具
#composer是什么 Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. composer出现之前我们php项目依赖管理大部分都是手动 ...
- yarn依赖管理工具的使用
Yarn是Facebook发布的一款依赖管理工具,它比npm更快.更高效. 与NPM命令对照 npm install => yarn install npm install --save [pa ...
- Golang依赖管理工具:glide从入门到精通使用
这是一个创建于 2017-07-22 05:33:09 的文章,其中的信息可能已经有所发展或是发生改变. 介绍 不论是开发Java还是你正在学习的Golang,都会遇到依赖管理问题.Java有牛逼轰轰 ...
- PHP的依赖管理工具----composer
安装Composer 参考:https://getcomposer.org/doc/01-basic-usage.md composer 是PHP依赖管理工具 PHP最低版本要求5.3.2,需要允许o ...
- 有用PHP依赖管理工具Composer新手教程
PHP依赖管理工具Composer新手教程 Composer 是 PHP 的一个依赖管理工具.它同意你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 依赖管理 Composer 不是一个包管理 ...
- golang多个项目时如何配置GOPATH,使用gb包依赖管理工具,不同项目配置不同的GOPATH的
golang多个项目时如何配置GOPATH,使用gb包依赖管理工具,不同项目配置不同的GOPATH的 1:执行脚本setGoPath.sh#!/bin/bashif [[ $GOPATH =~ .*$ ...
随机推荐
- angular JS中 ‘=’与angular.copy的区别
先来看代码: <b>{{test1}}</b> <input type="text" ng-model="test2" title ...
- protobuf, python Enum
继承enum.Enum的python class,其实是一个, name-value的关系,可以直接className(value)得到一个类.比如 import enum class xx(enum ...
- 【题解】Luogu P5301 [GXOI/GZOI2019]宝牌一大堆
原题传送门 首先先要学会麻将,然后会发现就是一个暴力dp,分三种情况考虑: 1.非七对子国士无双,设\(dp_{i,j,k,a,b}\)表示看到了第\(i\)种牌,一共有\(j\)个\(i-1\)开头 ...
- 常用Java API之Ramdom--用代码模拟猜数小游戏
常用Java API之Ramdom Ramdom类用来生成随机数字.使用起来也是三个步骤: 1.导包 import java.util.Random; 2.创建 Random r = new Rand ...
- go 学习笔记---chan
如果说 goroutine 是 Go语言程序的并发体的话,那么 channels 就是它们之间的通信机制.一个 channels 是一个通信机制,它可以让一个 goroutine 通过它给另一个 go ...
- Prometheus监控学习笔记之容器监控Grafana模块
0x00 概述 Grafana 是一个开源的,可以用于大规模指标数据的可视化项目,甚至还能对指标进行报警.基于友好的 Apache License 2.0 开源协议,目前是prometheus监控展示 ...
- Java中守护线程的总结 thread.setDaemon(true)
https://www.cnblogs.com/ziq711/p/8228255.html 在Java中有两类线程:User Thread(用户线程).Daemon Thread(守护线程) 用个比较 ...
- Excel导出,添加有效性
#region 添加有效性 DataTable dt = LAbll.LogisticsAccounts(DeptId); //查数据 if (dt.Rows.Count < 20) //有效 ...
- C#读写调整UVC摄像头画面-饱和度
有时,我们需要在C#代码中对摄像头的饱和度进行读和写,并立即生效.如何实现呢? 建立基于SharpCamera的项目 首先,请根据之前的一篇博文 点击这里 中的说明,建立基于SharpCamera的摄 ...
- azure 上传blob到ams(CreateFromBlob)
遇到的错误:The destination storage credentials must contain the account key credentials,参数名: destinationS ...