govendor用法
为什么使用govendor
go语言的依赖管理最主要的是版本控制问题。
govendor是Golang的依赖包管理工具,它的出现可以避免不同用户在clone同一个项目后从外部获取不同依赖库版本的问题。
govendor会将项目需要的依赖包添加到项目的vendor目录下,并且该目录中vendor.json文件会保存添加的依赖包的路径等信息。
Golang项目中的go文件在查找依赖的顺序是,先在vendor中查找,vendor没找到然后在GOPATH中查找,都没找到最后在GOROOT中查找。
govendor只是用来管理项目的依赖包,如果GOPATH中本身没有项目的依赖包,则需要通过go get先下载到GOPATH中,再通过govendor add +external拷贝到vendor目录中。
基本用法
安装govendor:go get -u github.com/kardianos/govendor
如果需要使用vendor的项目原本没有vendor,那么需要在该项目的目录下创建vendor
govendor init
之后如果需要添加依赖包,可以通过以下两种方式添加
govendor fetch 依赖包路径
govendor add 依赖包路径
.gitignore的配置:
/vendor/*
!/vendor/vendor.json
根据vendor.json下载依赖:govendor sync
govendor用法例子:
cd path/to/project
govendor init
govendor fetch project_url_with_out_http
cat vendor/vendor.json
govendor常用命令
- 增加包,搜add,会得到add和fetch这2个命令。
- 更新包,搜update,会得到update和fetch这2个命令。
- 删除包,搜remove,得到remove这个命令。
- 查看已经依赖的包,搜list,得到list、status、license命令,而符合你的是list,并且知道了status能列出过期的包。
➜ project_name git:(develop) govendor --help
govendor (v1.0.9): record dependencies and copy into vendor folder
-govendor-licenses Show govendor's licenses.
-version Show govendor version
-cpuprofile 'file' Writes a CPU profile to 'file' for debugging.
-memprofile 'file' Writes a heap profile to 'file' for debugging.
Sub-Commands
init Create the "vendor" folder and the "vendor.json" file.
list List and filter existing dependencies and packages.
add Add packages from $GOPATH.
update Update packages from $GOPATH.
remove Remove packages from the vendor folder.
status Lists any packages missing, out-of-date, or modified locally.
fetch Add new or update vendor folder packages from remote repository.
sync Pull packages into vendor folder from remote repository with revisions
from vendor.json file.
migrate Move packages from a legacy tool to the vendor folder with metadata.
get Like "go get" but copies dependencies into a "vendor" folder.
license List discovered licenses for the given status or import paths.
shell Run a "shell" to make multiple sub-commands more efficient for large
projects.
go tool commands that are wrapped:
"+status" package selection may be used with them
fmt, build, install, clean, test, vet, generate, tool
Status Types
+local (l) packages in your project
+external (e) referenced packages in GOPATH but not in current project
+vendor (v) packages in the vendor folder
+std (s) packages in the standard library
+excluded (x) external packages explicitly excluded from vendoring
+unused (u) packages in the vendor folder, but unused
+missing (m) referenced packages but not found
+program (p) package is a main package
+outside +external +missing
+all +all packages
Status can be referenced by their initial letters.
Package specifier
<path>[::<origin>][{/...|/^}][@[<version-spec>]]
Ignoring files with build tags, or excluding packages from being vendored:
The "vendor.json" file contains a string field named "ignore".
It may contain a space separated list of build tags to ignore when
listing and copying files.
This list may also contain package prefixes (containing a "/", possibly
as last character) to exclude when copying files in the vendor folder.
If "foo/" appears in this field, then package "foo" and all its sub-packages
("foo/bar", …) will be excluded (but package "bar/foo" will not).
By default the init command adds the "test" tag to the ignore list.
If using go1.5, ensure GO15VENDOREXPERIMENT=1 is set.
| 命令 | 功能 |
|---|---|
| init | 初始化 vendor 目录 |
| list | 列出所有的依赖包 |
| add | 添加包到 vendor 目录,如 govendor add +external 添加所有外部包 |
| add | PKG_PATH 添加指定的依赖包到 vendor 目录 |
| update | 从 $GOPATH 更新依赖包到 vendor 目录 |
| remove | 从 vendor 管理中删除依赖 |
| status | 列出所有缺失、过期和修改过的包 |
| fetch | 添加或更新包到本地 vendor 目录 |
| sync | 本地存在 vendor.json 时候拉去依赖包,匹配所记录的版本 |
| get | 类似 go get 目录,拉取依赖包到 vendor 目录 |
govendor用法的更多相关文章
- Go 包依赖管理工具 —— govendor
govendor 是一个基于 vendor 机制实现的 Go 包依赖管理命令行工具.与原生 vendor 无侵入性融合,也支持从其他依赖管理工具迁移,可以很方便的实现同一个包在不同项目中不同版本.以及 ...
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
- [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...
- 【JavaScript】innerHTML、innerText和outerHTML的用法区别
用法: <div id="test"> <span style="color:red">test1</span> tes ...
- chattr用法
[root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...
随机推荐
- 2.1 Scala语言概述
一.编程范式 命令式编程没有办法充分利用多核CPU: 函数式编程很多变量是不可修改的. 二.Scala简介 特点 scala运行在JVM上,兼容现有的Java程序: 面向对象的编程语言: 一门函数式语 ...
- P3731 [HAOI2017]新型城市化(tarjan+网络流)
洛谷 题意: 给出两个最大团的补图,现在要求增加一条边,使得最大最大团个数增加至少\(1\). 思路: 我们求出团的补图,问题可以转换为:对于一个二分图,选择删掉一条边,能够增大其最大独立集的点集数. ...
- JS高阶---为什么说JS是单线程执行的???
大纲: [主体] (1)如何证明JS运行是单线程的? 上述代码执行顺序结果为:fn()→timeout →timeout 接下来对上述代码做下修改 执行结果如右图所示 接下来点击确认,关闭弹框,再往后 ...
- 201871020225-牟星源《面向对象程序设计(java)》第十四周学习总结
201871020225-牟星源<面向对象程序设计(java)>第十四周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...
- C++双线性插值-片段
代码不能直接使用. for (int j = strRY; j<endRY; ++j) { float * pR = result.ptr<float>(j); for (int i ...
- SpringBoot设置支持跨域请求
跨域:现代浏览器出全的考虑,在http/https请求时必须遵守同源策略,否则即使跨域的http/https 请求,默认情况下是被禁止的,ip(域名)不同.或者端口不同.协议不同(比如http.htt ...
- zz【重磅】微软开源自动机器学习工具 - NNI
[重磅]微软开源自动机器学习工具 - NNI 在机器学习建模时,除了准备数据,最耗时耗力的就是尝试各种超参组合,找到模型最佳效果的过程了.即使是对于有经验的算法工程师和数据科学家,有时候也很难把握其中 ...
- javascript专题系列--js乱序
乱序的意思想必没有不知道:就是将数组打乱. 听到乱序一般都会想到js的随机函数Math.random(); var values = [1, 2, 3, 4, 5]; values.sort(func ...
- 微信小程序开发工具调试没问题,真机调试Provisional headers are shown
from: https://blog.csdn.net/github_38928905/article/details/83105523 在开发工具调试,请求正常没问题,使用真机调试,请求异常:Pro ...
- MySQL实战45讲学习笔记:第二十三讲
一.本节概要 今天这篇文章,我会继续和你介绍在业务高峰期临时提升性能的方法.从文章标题“MySQL 是怎么保证数据不丢的?”,你就可以看出来,今天我和你介绍的方法,跟数据的可靠性有关. 在专栏前面文章 ...