網(wǎng)上寫govendor的博文不少惦蚊,但從安裝到介紹器虾,總看上去有些沉重,下面奉上一篇簡(jiǎn)單的教程蹦锋,3分鐘入門兆沙。
第1部分 簡(jiǎn)明教程
2步走,3分鐘輕松搞定Go項(xiàng)目的依賴莉掂。
第1步 安裝
go get -u github.com/kardianos/govendor
第2步 為項(xiàng)目增加依賴
- 進(jìn)入到項(xiàng)目目錄
- 使用
govendor init
命令初始化項(xiàng)目的依賴 - 運(yùn)行
govendor fetch
命令增加依賴 - 打開
./vendor/vendor.json
查看依賴的包
步驟:
cd path/to/project
govendor init
govendor fetch project_url_with_out_http
cat vendor/vendor.json
舉個(gè)例子:項(xiàng)目awesome依賴github.com/go-clang/bootstrap
葛圃,過(guò)程是這樣的:
cd awesome
govendor init
govendor fetch github.com/go-clang/bootstrap
cat vendor/vendor.json
第2部分 授之以漁
第1個(gè) 遇到govendor問(wèn)題
govendor當(dāng)然還有其他豐富功能,比如:
- 依賴的包更新了憎妙,怎么更新依賴库正?
- 不依賴這個(gè)包, 怎么移除尚氛?
- 怎么快速查看已經(jīng)依賴的包诀诊?
- 怎么知道哪些包過(guò)期了,或者丟失了阅嘶?
你可能想到時(shí)候遇到再百度或者Google一下属瓣,看看別人的博客或教程,這種方法太弱了讯柔,浪費(fèi)自己的時(shí)間抡蛙,不能專心工作。
正確的姿勢(shì):
- 使用
govendor --help
列出各種命令魂迄。 - 使用Ctrl+F開啟終端搜索粗截,尋找要使用的命令。
比如:
- 增加包捣炬,搜a(bǔ)dd熊昌,會(huì)得到add和fetch這2個(gè)命令绽榛。
- 更新包,搜update婿屹,會(huì)得到update和fetch這2個(gè)命令灭美。
- 刪除包,搜remove昂利,得到remove這個(gè)命令届腐。
- 查看已經(jīng)依賴的包,搜list蜂奸,得到list犁苏、status、license命令扩所,而符合你的是list围详,并且知道了status能列出過(guò)期的包。
? project_name git:(develop) govendor --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.
第2個(gè) govendor做了啥
govendor“安裝”軟件包的時(shí)候做了啥呢祖屏?其實(shí)就是把依賴的包下載到project_dir/vendor
目錄短曾,這個(gè)目錄結(jié)構(gòu)和$GOPATH/src
下的相同,但如果下載一些比較大的會(huì)發(fā)現(xiàn)赐劣,govendor并不會(huì)下載依賴包的所有文件嫉拐,而是上層的部分文件。想深入了解govendor魁兼?入門后再研究吧婉徘。
? awesome git:(master) ? tree .
.
├── awesome
├── hi.go
└── vendor
├── github.com
│ └── go-clang
│ └── bootstrap
│ ├── AUTHORS
│ ├── CONTRIBUTORS
│ ├── LICENSE
│ ├── Makefile
│ └── README.md
└── vendor.json
如果這篇文章對(duì)你有幫助,請(qǐng)點(diǎn)個(gè)贊/喜歡咐汞,讓我知道我的寫作是有價(jià)值的盖呼,感謝。