使用govendor管理Golang專案依賴
1、安裝govendor
go get -u -v github.com/kardianos/govendor
2、init
在專案根目錄,比如我這裡是tap專案,那就是進入tap目錄,執行init命令
govendor init
ls
cd vendor/
ls
這個 vendor.json 會類似 godep 工具中的描述檔案版本的功能。
3、執行命令將當前應用必須的檔案包含進來
//將外部依賴一同加入vendor中
govendor add +external
// 更新外部所有依賴
govendor update +external
4、vendor.json
vendor.json內容如下:
{
"comment": "",
"ignore": "test",
"package": [
{
"checksumSHA1": "Ufix4JjY69s87o5ftKQ39OcxvTU=",
"path": "github.com/Shopify/sarama",
"revision": "2fd980e23bdcbb8edeb78fc704de0c39a6567ffc",
"revisionTime": "2017-06-30T17:40:37Z"
},
{
"checksumSHA1": "sUP5RbqwDFzHiW538NBTJ3c57aw=",
"path": "github.com/bsm/sarama-cluster",
"revision": "f1ef2fda9bccc377dad24d7f7522d46b6a9a817b",
"revisionTime": "2017-07-31T13:08:41Z"
},
{
"checksumSHA1": "GcIrB1ug6mS8aG73v1KtlHfva9Q=",
"path": "github.com/davecgh/go-spew/spew",
"revision": "adab96458c51a58dc1783b3335dcce5461522e75",
"revisionTime": "2017-07-11T18:34:51Z"
},
{
"checksumSHA1": "o0psFRtB8EoelTAEhJSqrtXdwJY=",
"path": "github.com/eapache/go-resiliency/breaker",
"revision": "b1fe83b5b03f624450823b751b662259ffc6af70",
"revisionTime": "2017-06-07T16:36:15Z"
},
{
"checksumSHA1": "jZ/Z0i7G8a+9GQ7uOzUbLI/FubU=",
"path": "github.com/eapache/go-xerial-snappy",
"revision": "bb955e01b9346ac19dc29eb16586c90ded99a98c",
"revisionTime": "2016-06-09T14:24:08Z"
},
{
"checksumSHA1": "Jv+5MP/HXSnx830En3Iwmj9v7g0=",
"path": "github.com/eapache/queue",
"revision": "44cc805cf13205b55f69e14bcb69867d1ae92f98",
"revisionTime": "2016-08-05T00:47:13Z"
},
{
"checksumSHA1": "OV+/R43DDDJ/Gxrx9oQob/K7sL0=",
"path": "github.com/golang/snappy",
"revision": "553a641470496b2327abcac10b36396bd98e45c9",
"revisionTime": "2017-02-15T23:32:05Z"
},
{
"checksumSHA1": "imr1t7r6P5Bz7DGR2sxDymLWo7w=",
"path": "github.com/pierrec/lz4",
"revision": "5a3d2245f97fc249850e7802e3c01fad02a1c316",
"revisionTime": "2017-05-19T17:06:25Z"
},
{
"checksumSHA1": "ieRRw3MpbPjA3z2MJVHDsC9jkjc=",
"path": "github.com/pierrec/xxHash/xxHash32",
"revision": "a0006b13c722f7f12368c00a3d3c2ae8a999a0c6",
"revisionTime": "2017-07-14T08:24:55Z"
},
{
"checksumSHA1": "DIjooF5+DLH5JSOjqnBlfNh9dFU=",
"path": "github.com/rcrowley/go-metrics",
"revision": "1f30fe9094a513ce4c700b9a54458bbb0c96996c",
"revisionTime": "2016-11-28T21:05:44Z"
},
{
"checksumSHA1": "fAm2yk7tTesaQ5ivVUPjTpKlxdo=",
"path": "github.com/sirupsen/logrus",
"revision": "95cd2b9c79aa5e72ab0bc69b7ccc2be15bf850f6",
"revisionTime": "2017-11-18T12:42:23Z"
},
{
"checksumSHA1": "X1NTlfcau2XcV6WtAHF6b/DECOA=",
"path": "golang.org/x/crypto/ssh/terminal",
"revision": "94eea52f7b742c7cbe0b03b22f0c4c8631ece122",
"revisionTime": "2017-11-28T01:43:40Z"
},
{
"checksumSHA1": "B2t4JjkjyoUINOnKXviNypvgWpo=",
"path": "golang.org/x/sys/unix",
"revision": "bf42f188b9bc6f2cf5b8ee5a912ef1aedd0eba4c",
"revisionTime": "2017-11-10T14:41:19Z"
},
{
"checksumSHA1": "ck5uxoEeMDUL/QqPvGvBmcbsJzg=",
"path": "golang.org/x/sys/windows",
"revision": "bf42f188b9bc6f2cf5b8ee5a912ef1aedd0eba4c",
"revisionTime": "2017-11-10T14:41:19Z"
}
],
"rootPath": "git.XXX.net/monitor/tap"
}
5、govendor --help
$ 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.
OK,結束,可以用git將vendor提交到程式碼庫了。
本文參考:https://www.tuicool.com/articles/NjMzIbJ
個人微信公眾號:
作者:jiankunking 出處:http://blog.csdn.net/jiankunking
相關文章
- govendor依賴包管理Go
- 使用godep管理Golang專案依賴Golang
- golang 依賴管理Golang
- golang 快速入門 [7.1]-專案與依賴管理-gopathGolang
- 在python專案的docker映象裡使用pdm管理依賴PythonDocker
- 分散式專案中,選型與依賴管理分散式
- 專案管理中,如何識別和管理依賴關係?專案管理
- 依賴管理和依賴範圍
- 搭建react專案常用依賴React
- 在 xunit 測試專案中使用依賴注入依賴注入
- Maven中如何管理多模組專案的依賴關係Maven
- 如何管理前端專案中的複雜依賴關係前端
- idea gradle 專案依賴IdeaGradle
- Maven依賴管理:控制依賴的傳遞Maven
- 什麼是專案管理中的任務依賴關係專案管理
- 為你的專案依賴加星
- 在iOS專案中依賴Flutter Module-②遠端依賴Git資源iOSFlutterGit
- Python 專案及依賴管理工具技術選型Python
- 探索 JavaScript 中的依賴管理及迴圈依賴JavaScript
- 專案管理軟體中什麼是依賴管理,具體有什麼作用?專案管理
- 如何使用Maven將專案中的依賴打進jar包MavenJAR
- 如何建立依賴專案工程--android moduleAndroid
- 普通maven專案將依賴包打包方法Maven
- Android專案的依賴關係解析Android
- python如何匯出專案依賴【pipreqs】Python
- PHP依賴管理ComposerPHP
- Flutter 中的依賴管理Flutter
- Maven依賴管理系統Maven
- Go 專案依賴注入wire工具最佳實踐介紹與使用Go依賴注入
- Go 包管理工具 govendor 使用指南Go
- Golang 依賴注入設計哲學|12.6K 🌟 的依賴注入庫 wireGolang依賴注入
- JavaScript專案中鎖定npm依賴包版本JavaScriptNPM
- Springboot專案依賴jar分離部署Spring BootJAR
- IDEA中Maven顯示存在依賴但專案中並未匯入依賴JARIdeaMavenJAR
- webapi - 使用依賴注入WebAPI依賴注入
- 關於Golang中的依賴注入實現Golang依賴注入
- 使用Gradle檢視Android專案中庫的依賴關係GradleAndroid
- go module,使用gitlab私有倉庫作為專案的依賴包GoGitlab