目录
命令 | 描述 | 功能 |
init | Create the "vendor" folder and the "vendor.json" file. | 创建vendor目录以及(空)vendor.json |
list | List and filter existing dependencies and packages. | 查询当前已存在依赖 |
add | Add packages from $GOPATH. | 从GOPATH拷贝依赖到vendor目录 |
update | Update packages from $GOPATH. | 从GOPATH更新依赖到vendor目录 |
remove | Remove packages from the vendor folder. | 从vendor目录移除依赖 |
status | Lists any packages missing, out-of-date, or modified locally. | 查看依赖是否丢失,过期或者修改的依赖 |
fetch | Add new or update vendor folder packages from remote repository. | 远程添加或者更新依赖到vendor目录 |
sync | Pull packages into vendor folder from remote repository with revisions from vendor.json file. | 远程同步vendor.json所有依赖到vendor目录 |
migrate | Move packages from a legacy tool to the vendor folder with metadata. | 合并其他vendor目录到本vendor目录下 |
get | Like "go get" but copies dependencies into a "vendor" folder. | 远程直接下载依赖到vendor目录下 |
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. | 用于大型项目中子命令支持 |
命令 | 描述 | 功能 |
+local | (l) packages in your project | 限定在本项目 |
+external | (e) referenced packages in GOPATH but not in current project | 限定在GOPATH |
+vendor | (v) packages in the vendor folder | 限定在vendor |
+std | (s) packages in the standard library | 限定在GOROOT |
+excluded | (x) external packages explicitly excluded from vendoring | 限定vendor排除的 |
+unused | (u) packages in the vendor folder, but unused | 限定vendor未使用 |
+missing | (m) referenced packages but not found | 限定vendor缺失的 |
+program | (p) package is a main package | 限定main包下的 |
+outside | +external +missing | 组合vendor缺失在GOPATH的 |
+all | +all packages | 所有包 |
https://blog.csdn.net/qq_22211217/article/details/101116308
vendor基于GOPATH,所有项目必须在GOPATH/src下
go get -u github.com/kardianos/govendor
ps:go get 相当于git clone与 go install
其执行文件在GOPATH/bin/govendor.exe
等效:
使用git clone 将 github.com/kardianos/govendor下载到GOPATH/src下
再进入GOPATH/src/github.com/kardianos/govendor 使用go install main.go
%GOPATH%/src/govendor-demo ##在此目录下建立项目叫gomod-demo
%GOPATH%/src/govendor-demo/main.go ##在项目目录新建src文件夹并创建main.go
##########################项目结构#########################
govendor-demo
└─main.go
##########################main.go ########################
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
router := gin.Default()
router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello World")
})
router.Run(":8000")
}
go get -u github.com/gin-gonic/gin ##下载依赖到GOPATH/src
ps:go get命令下载位置由其他插件控制 若使用vgo 则下载位置将在GOPATH/pkg/mod需要手动git clone
完整的包装规格为: <path>[{/...|/^}][::<origin>][@[<version-spec>]]
一些例子:
github.com/kardianos/govendor 指定单个程序包和单个文件夹。
github.com/kardianos/govendor/...指定govendor该路径下的所有引用包。
github.com/kardianos/govendor/^指定govendor文件夹和所有子文件夹。对于资源或不需要部分存储库很有用。
github.com/kardianos/govendor/^::github.com/myself/govendor 与上述相同,但从用户“ myself”获取。
github.com/kardianos/govendor/...@abc12032所有参考的修订版软件包abc12032。
github.com/kardianos/govendor/...@v1 与上述相同,但获取最新的“ v1”标签,例如“ v1.4.3”。
github.com/kardianos/govendor/...@=v1 获取确切的版本“ v1”。
若需要使用govendor进行依赖管理
cd /d %GOPATH%/src/govendor-demo ##切换项目根目录
govendor init ##生成vendor目录和vendor.json文件
#######################生成vendor文件夹#################################
govendor-demo
├─vendor
│ └─vendor.json
└─main.go
#####################vendor.json#######################################
{
"comment": "",
"ignore": "test",
"package": [
{
"checksumSHA1": "mKall8xfKBPL/a5Ji//i968rLsY=",
"path": "github.com/gin-contrib/sse",
"revision": "43f0f29dbd2b3f0feeebff91fd9cda22db296938",
"revisionTime": "2019-09-05T05:13:34Z"
}
...省略
],
"rootPath": "govendor-demo"
}
govendor init ##初始化vendor
govendor list -v ##查看vendor依赖
govendor add -e ##从GOPATH添加vendor未添加的依赖
govendor fetch -e ##从GOPATH批量更新或添加vendor未添加的依赖
govendor sync ##根据已有的vendor.json里面的依赖包信息。从远程拉取包到vendor目录下