govendor 使用文档

GO管理工具 govendor

主页:

github.com/kardianos/govendor

快速安装使用:

go get -u github.com/kardianos/govendor

安装之后,会在 GOPATH/bin目录下面。 (工作目录下)

流程


# 1、创建项目,在GOPATH目录下,
# 2、使用 govendor init 初始化项目,生成vendor 文件夹和 vendor/vendor.json文件。
# 3、使用 govendor add +external 添加已存在GOPATH中的依赖包到vendor文件夹中。

# 4、使用 govendor remove 移除已添加的包依赖。结果,从vendor文件夹中删除该包,并更新vendor/vendor.json文件。
# 5、使用 govendor status 查看所有缺失、过期和修改过的包。

# 5、使用 govendor list / govendor list -v packagename 查看依赖。

# 6、使用 govendor fetch  指定要获取的特定版本或修订版本,如下:
    govendor fetch golang.org/x/net/context@a4bbce9fcae005b22ae5443f6af064d80a6f5a55
    govendor fetch golang.org/x/net/context@v1   # Get latest v1.*.* tag or branch.
    govendor fetch golang.org/x/net/context@=v1  # Get the tag or branch named "v1".

# 7、使用 govendor sync 下载依赖包,根据vendor/vendor.json中的版本信息进行远程下载到本地中。

常用命令


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


  • 初始化- govendor init

在当前GOPATH/src 目录下面创建 go-project-layout 目录,然后执行 govendor init


$ pwd
src/go-project-layout
$ govendor init
$ ls
vendor/

执行 govendor init 命令后,会在当前项目 go-project-layout 中生成 vendor 以及 vendor/vendor.json 文件。

  • 添加依赖包 - govendor add +external / govendor add +e (缩写)
$ govendor add +external

$ ls vendor/
github.com/  golang.org/  gopkg.in/  vendor.json

此命令是添加 项目中所需要的依赖包 到vendor 文件夹中,并更新vendor/vendor.json
该依赖包是已经存在 GOPATH 中,如果不存在本地GOPATH中,则通过 go get 下载,
然后在使用 govendor add +external 添加依赖到vendor 文件夹中。

  • 查看所有依赖包命令
$ govendor list
 v  github.com/BurntSushi/toml
 v  github.com/Joker/jade
 v  github.com/Shopify/goreferrer
 e  github.com/Shopify/goreferrer
 e  github.com/aymerick/raymond
 e  github.com/aymerick/raymond/ast
 e  github.com/aymerick/raymond/lexer
 e  github.com/aymerick/raymond/parser

# 查看 一个包 在哪些位置中调用

# 查看 fmt 包 在项目中 哪些地方种调用了。
$ govendor list -v fmt 
 s  fmt
    ├──  e  github.com/kataras/iris/vendor/github.com/BurntSushi/toml
    ├──  e  github.com/kataras/iris/vendor/github.com/Joker/jade
    ├──  e  github.com/kataras/iris/vendor/github.com/aymerick/raymond
    ├──  e  github.com/kataras/iris/vendor/github.com/aymerick/raymond/ast
    ├──  e  github.com/kataras/iris/vendor/github.com/aymerick/raymond/lexer
    ├──  e  github.com/kataras/iris/vendor/github.com/aymerick/raymond/parser
    ├──  e  github.com/kataras/iris/vendor/github.com/eknkc/amber
    ├──  e  github.com/kataras/iris/vendor/github.com/eknkc/amber/parser
    ├──  e  github.com/kataras/iris/vendor/github.com/fatih/structs
    ├──  e  github.com/kataras/iris/vendor/github.com/flosch/pongo2
    ├──  e  github.com/kataras/iris/vendor/github.com/iris-contrib/blackfriday
    ├──  e  github.com/kataras/iris/vendor/github.com/iris-contrib/formBinder
    ├──  e  github.com/kataras/iris/vendor/github.com/iris-contrib/go.uuid
    ├──  e  github.com/kataras/iris/vendor/github.com/json-iterator/go
    ├──  e  github.com/kataras/iris/vendor/github.com/flosch/pongo2/vendor/github.com/juju/errors

依赖包的类型如下

  • v 状态是: +vendor 缩写 v 表示已经添加到vendor目录下面。

  • e 状态是: +external 缩写 e 表示外部包,有GOPATH来管理。没有添加到vendor文件夹中。

  • l 状态是: +local 缩写, 表示本地包,表示项目目录的包组织。

  • s 状态是: +std 缩写,表示Go语言中的标准包。

  • m 状态是: +missing 缩写,表示代码中引用了依赖包,但是没有找到该包。

  • 添加指定包到 - govendor add github.com/pkg/errors

# 例如: 添加 github.com/pkg/errors 

$ govendor.exe add github.com/pkg/errors

$ cat  vendor.json
 {
         "comment": "",
         "ignore": "test",
         "package": [
                 {
                         "checksumSHA1": "CUU7ZZtxuc1mpbM8XKrSTNiy/yM=",
                         "path": "github.com/pkg/errors",
                         "revision": "27936f6d90f9c8e1145f11ed52ffffbfdb9e0af7",
                         "revisionTime": "2019-02-27T00:00:51Z"
                 }
         ],
         "rootPath": "go-project-layout"
 }

你可能感兴趣的:(golang,golang)