【golang学习笔记】go依赖管理之govendor

前述

我们都知道php以及java都有自己的依赖包管理工具,那么go有吗?当然有的,go到了1.5版本时代,官方引入包管理的设计,加了 vendor 目录来支持本地包管理依赖。官方 wiki 推荐了多种支持这种特性的包管理工具,如:Godep、gv、gvt、glide、govendor等。

govendor

简介

对于 govendor 来说,主要存在三种位置的包:项目自身的包组织为本地(local)包;传统的存放在 $GOPATH 下的依赖包为外部(external)依赖包;被 govendor 管理的放在 vendor 目录下的依赖包则为 vendor 包。

对于 govendor 来说,依赖包主要有以下多种类型:

状态 缩写状态 含义
+local l 本地包,即项目自身的包组织
+external e 外部包,即被 $GOPATH 管理,但不在 vendor 目录下
+vendor v 已被 govendor 管理,即在 vendor 目录下
+std s 标准库中的包
+unused u 未使用的包,即包在 vendor 目录下,但项目并没有用到
+missing m 代码引用了依赖包,但该包并没有找到
+program p 主程序包,意味着可以编译为执行文件
+outside 外部包和缺失的包
+all 所有的包

安装

  1. 下载govendor包

    go get -u github.com/kardianos/govendor

  2. 命令行执行 bin/govendor,若出现以下信息,则说明安装成功

    ➜ ~ govendor
    govendor (v1.0.8): record dependencies and copy into vendor folder
    -govendor-licenses Show govendor’s licenses.
    -version Show govendor version

  3. 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

4. 其他:

The project must be within a $GOPATH/src.

If using go1.5, ensure you set GO15VENDOREXPERIMENT=1.

猜你喜欢

转载自blog.csdn.net/zf766045962/article/details/81216161