使用govendor管理Golang项目依赖

1、安装govendor

go get -u -v github.com/kardianos/govendor

2、init

在项目根目录,比如我这里是tap项目,那就是进入tap目录,执行init命令

govendor init
ls
cd vendor/
ls


这个 vendor.json 会类似 godep 工具中的描述文件版本的功能

3、执行命令将当前应用必须的文件包含进来

govendor add +external

4、vendor.json

vendor.json内容如下:

{
    "comment": "","ignore": "test","package": [ { "checksumSHA1": "Ufix4JjY69s87o5ftKQ39OcxvTU=","path": "github.com/Shopify/Sarama","revision": "2fd980e23bdcbb8edeb78fc704de0c39a6567ffc","revisionTime": "2017-06-30T17:40:37Z" },{ "checksumSHA1": "sUP5RbqwDFzHiW538NBTJ3c57aw=","path": "github.com/bsm/Sarama-cluster","revision": "f1ef2fda9bccc377dad24d7f7522d46b6a9a817b","revisionTime": "2017-07-31T13:08:41Z" },{ "checksumSHA1": "GcIrB1ug6mS8aG73v1KtlHfva9Q=","path": "github.com/davecgh/go-spew/spew","revision": "adab96458c51a58dc1783b3335dcce5461522e75","revisionTime": "2017-07-11T18:34:51Z" },{ "checksumSHA1": "o0psFRtB8EoelTAEhJSqrtXdwJY=","path": "github.com/eapache/go-resiliency/breaker","revision": "b1fe83b5b03f624450823b751b662259ffc6af70","revisionTime": "2017-06-07T16:36:15Z" },{ "checksumSHA1": "jZ/Z0i7G8a+9GQ7uOzUbLI/FubU=","path": "github.com/eapache/go-xerial-snappy","revision": "bb955e01b9346ac19dc29eb16586c90ded99a98c","revisionTime": "2016-06-09T14:24:08Z" },{ "checksumSHA1": "Jv+5MP/HXSnx830En3Iwmj9v7g0=","path": "github.com/eapache/queue","revision": "44cc805cf13205b55f69e14bcb69867d1ae92f98","revisionTime": "2016-08-05T00:47:13Z" },{ "checksumSHA1": "OV+/R43DDDJ/Gxrx9oQob/K7sL0=","path": "github.com/golang/snappy","revision": "553a641470496b2327abcac10b36396bd98e45c9","revisionTime": "2017-02-15T23:32:05Z" },{ "checksumSHA1": "imr1t7r6P5Bz7DGR2sxDymLWo7w=","path": "github.com/pierrec/lz4","revision": "5a3d2245f97fc249850e7802e3c01fad02a1c316","revisionTime": "2017-05-19T17:06:25Z" },{ "checksumSHA1": "ieRRw3MpbPjA3z2MJVHDsC9jkjc=","path": "github.com/pierrec/xxHash/xxHash32","revision": "a0006b13c722f7f12368c00a3d3c2ae8a999a0c6","revisionTime": "2017-07-14T08:24:55Z" },{ "checksumSHA1": "DIjooF5+DLH5JSOjqnBlfNh9dFU=","path": "github.com/rcrowley/go-metrics","revision": "1f30fe9094a513ce4c700b9a54458bbb0c96996c","revisionTime": "2016-11-28T21:05:44Z" },{ "checksumSHA1": "fAm2yk7tTesaQ5ivVUPjTpKlxdo=","path": "github.com/sirupsen/logrus","revision": "95cd2b9c79aa5e72ab0bc69b7ccc2be15bf850f6","revisionTime": "2017-11-18T12:42:23Z" },{ "checksumSHA1": "X1NTlfcau2XcV6WtAHF6b/DECOA=","path": "golang.org/x/crypto/ssh/terminal","revision": "94eea52f7b742c7cbe0b03b22f0c4c8631ece122","revisionTime": "2017-11-28T01:43:40Z" },{ "checksumSHA1": "B2t4JjkjyoUINOnKXviNypvgWpo=","path": "golang.org/x/sys/unix","revision": "bf42f188b9bc6f2cf5b8ee5a912ef1aedd0eba4c","revisionTime": "2017-11-10T14:41:19Z" },{ "checksumSHA1": "ck5uxoEeMDUL/QqPvGvBmcbsJzg=","path": "golang.org/x/sys/windows","revisionTime": "2017-11-10T14:41:19Z" } ],"rootPath": "git.XXX.net/monitor/tap" }

5、govendor –help

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

OK,结束,可以用git将vendor提交到代码库了。

本文参考:https://www.tuicool.com/articles/NjMzIbJ

使用godep管理Golang项目依赖

个人微信公众号:

作者:jiankunking 出处:http://blog.csdn.net/jiankunking

相关文章

什么是Go的接口? 接口可以说是一种类型,可以粗略的理解为他...
1、Golang指针 在介绍Golang指针隐式间接引用前,先简单说下...
1、概述 1.1&#160;Protocol buffers定义 Protocol buffe...
判断文件是否存在,需要用到"os"包中的两个函数: os.Stat(...
1、编译环境 OS :Loongnix-Server Linux release 8.3 CPU指...
1、概述 Golang是一种强类型语言,虽然在代码中经常看到i:=1...