cd  到工程目录。

govendor init : 初始化

govendor fetch : 拉取包

go 1.6以后编译go代码会优先从vendor目录先寻找依赖包;

controllers\articleController.go:6:2: cannot find package "github.com/gin-gonic/gin" in any of:
E:\gocode\src\gin_demo\vendor\github.com\gin-gonic\gin (vendor tree)
C:\Go\src\github.com\gin-gonic\gin (from $GOROOT)
E:\gocode\src\github.com\gin-gonic\gin (from $GOPATH)

先从vendor下面找,再去GOROOT下面找,最后去GOPATH去找。

go vendor 是go 1.5 官方引入管理包依赖的方式,1.6正式引入

其基本思路是,将引用的外部包的源代码放在当前工程的vendor目录下面,go 1.6以后编译go代码会优先从vendor目录先寻找依赖包;

1.解决的问题:
将源码拷贝到当前工程的vendor目录下,这样打包当前的工程代码到任意机器的$GOPATH/src下都可以通过编译,避免项目代码外部依赖过多,迁移后,
需要多次go get 外包依赖包;而且通过go get 重新拉去的外部依赖包的版本可能和工程开发时使用的不一致,导致编译错误问题。 2.未解决的问题:
无法精确的引用外部包进行版本控制,不能指定引用某个特定版本的外部包;只是在开发时,将其拷贝过来,但是一旦外部包升级,vendor下的代码不会跟着升级,
而且vendor下面并没有元文件记录引用包的版本信息,这个引用外部包升级产生很大的问题,无法评估升级带来的风险; 3.解决go vendor未解决的问题 使用govendor ,其有如下好处:
https://github.com/kardianos/govendor
1>.可以平滑的将现有非vendor项目转换为vendor项目
govendor add inport_out_packagename
2>会生成一个元数据文件,记录项目工程依赖的外部包,以及其版本信息
vendor/vendor.json
3>提供命令查看整个工程的依赖关系
goverdor --list
goverdor --list -v project:
https://github.com/kardianos/govendor
Sub-commands

    init     Create the "vendor" folder and the "vendor.json" file.                 #创建一个vendor目录并生成个空的verdor.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 #一句本地vendor/verdor.json文件指定的包机器版本信息从远程资源库拉取资源
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. #等于go get 但是同步外部依赖包到vendor目录,而不是$GOPATH/src
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

Packages can be specified by their "status".

    +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 explicitely 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
05-23 18:51