govendor

安装

go get -u github.com/kardianos/govendor

初始化

在项目根目录下执行以下命令进行vendor初始化:
govendor init

项目根目录下即会自动生成 vendor 目录和 vendor.json 文件

常用命令
  • 将 已被引用 且在 $GOPATH 下的所有包复制到vendor目录
    govendor add +external

  • 仅从 $GOPATH 中复制指定包
    govendor add gopkg.in/yaml.v2

  • 列出代码中所有被引用到的包及其状态
    govendor list

  • 从远程仓库添加或更新某个包(不会在 $GOPATH 也存一份)
    govendor fetch golang.org/x/net/context

  • 安装指定版本的包

    1
    2
    3
    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".
  • 删除vendor中已有 但是代码中未使用的包
    govendor remove +unused