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"
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
go mod vendor是一个命令行工具,用于将主模块的vendor目录重置为包含构建和测试所有主模块包所需的所有包。它不包括供应商包的测试代码。如果主模块的根目录中存在vendor目录,并且主模块的go.mod文件中的go版本为1.14或更高版本,则会自动使用vendor目录。要显式启用供应商功能,请使用标志-mod=vendor。要禁用供应商功能,请使用标志-mod=readonly或-mod=mod。go mod vendor还有其他好处,例如当从版本控制系统中删除依赖项或代理服务器丢失模块时,可以使用vendor解决问题。此外,它还可以帮助您跟踪和调试依赖项,并在需要时进行测试更改。运行go mod tidy和go mod vendor后,您的更改将被替换。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *2* [Go:go mod vendor 使用](https://blog.csdn.net/test1280/article/details/120855865)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Vendor使用golangvendor是个啥?](https://blog.csdn.net/qq_39458487/article/details/124803432)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值