使用govendor管理Golang專案依賴

衣舞晨風發表於2017-12-30

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、執行命令將當前應用必須的檔案包含進來

//將外部依賴一同加入vendor中
govendor add +external
// 更新外部所有依賴
govendor update +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",
			"revision": "bf42f188b9bc6f2cf5b8ee5a912ef1aedd0eba4c",
			"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

相關文章