> For the complete documentation index, see [llms.txt](https://yangsx95.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yangsx95.gitbook.io/notes/programming-language/golang/build-tools/govendor.md).

# Go Vendor

## 安装 govendor

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

## 使用 govendor

```
# 创建vendor目录，创建vendor.json文件
govendor init

# 将GOPATH中本工程使用到的依赖包自动移动到vendor目录中
# 必须vendor目录下没有，且vendor.json中没有记录这个包的时候才会添加
govendor add +external

# 拉取远程包
# 从远程拉取包到vendor下并记录进vendor.json，gopath目录下不会有拉下来的包
govendor fetch github.com/BurntSushi/toml

# 根据已有的vendor.json里面的依赖包信息。从远程拉取包到vendor目录下
govendor sync

# 生成依赖包 
# 移除包的时候会把vendor目录和json文件的记录一起移除，只有vendor或者只有json中有仍然会移除而不提示
govendor remove +local

# 移除vendor下所有的包
govendor remove +vendor

# 更新vendor的包命令
govendor update +vendor
```

> 项目需要在 GOPATH src 路径下
