【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 来说,依赖包主要有以下多种类型:

状态缩写状态含义
+locall本地包,即项目自身的包组织
+externale外部包,即被 $GOPATH 管理,但不在 vendor 目录下
+vendorv已被 govendor 管理,即在 vendor 目录下
+stds标准库中的包
+unusedu未使用的包,即包在 vendor 目录下,但项目并没有用到
+missingm代码引用了依赖包,但该包并没有找到
+programp主程序包,意味着可以编译为执行文件
+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
命令含义
initCreate the “vendor” folder and the “vendor.json” file.
listList and filter existing dependencies and packages.
addAdd packages from $GOPATH.
updateUpdate packages from $GOPATH.
removeRemove packages from the vendor folder.
statusLists any packages missing, out-of-date, or modified locally.
fetchAdd new or update vendor folder packages from remote repository.
syncPull packages into vendor folder from remote repository with revisions from vendor.json file.
migrateMove packages from a legacy tool to the vendor folder with metadata.
getLike “go get” but copies dependencies into a “vendor” folder.
licenseList discovered licenses for the given status or import paths.
shellRun 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值