Golang包管理工具之govendor的使用

Golang包管理工具之govendor的使用

轉(zhuǎn)載:https://blog.csdn.net/huwh_/article/details/77169858

介紹

golang工程的依賴包經(jīng)常使用go get命令來獲取迎捺,例如:go get github.com/kardianos/govendor ,會將依賴包下載到GOPATH的路徑下揍障。

常用的依賴包管理工具有g(shù)odep肮之,govendor等择镇,在Golang1.5之后累铅,Go提供了 GO15VENDOREXPERIMENT 環(huán)境變量(Go 1.6版本默認開啟該環(huán)境變量),用于將go build時的應(yīng)用路徑搜索調(diào)整成為 當(dāng)前項目目錄/vendor 目錄方式眷篇。通過這種形式愤惰,我們可以實現(xiàn)類似于 godep 方式的項目依賴管理苇经。

安裝使用

安裝

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

使用

#進入到項目目錄
cd /home/gopath/src/mytool

#初始化vendor目錄
govendor init

#查看vendor目錄
[root@CC54425A mytool]# ls
commands  main.go  vendor  mytool_test.sh

#將GOPATH中本工程使用到的依賴包自動移動到vendor目錄中
#說明:如果本地GOPATH沒有依賴包,先go get相應(yīng)的依賴包
govendor add +external
或使用縮寫: govendor add +e 

#Go 1.6以上版本默認開啟 GO15VENDOREXPERIMENT 環(huán)境變量宦言,可忽略該步驟扇单。
#通過設(shè)置環(huán)境變量 GO15VENDOREXPERIMENT=1 使用vendor文件夾構(gòu)建文件。
#可以選擇 export GO15VENDOREXPERIMENT=1 或 GO15VENDOREXPERIMENT=1 go build 執(zhí)行編譯

export GO15VENDOREXPERIMENT=1

說明

govendor只是用來管理項目的依賴包奠旺,如果GOPATH中本身沒有項目的依賴包蜘澜,則需要通過go get先下載到GOPATH中,再通過govendor add +external拷貝到vendor目錄中响疚。Go 1.6以上版本默認開啟GO15VENDOREXPERIMENT環(huán)境變量鄙信。

使用命令

[root@CC54425A mytool]# govendor
govendor (v1.0.8): 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.

vendor.json

govendor配置文件,記錄依賴包列表忿晕。

{
    "comment": "",
    "ignore": "test",
    "package": [
        {
            "checksumSHA1": "uGalSICR4r7354vvKuNnh7Y/R/4=",
            "path": "github.com/urfave/cli",
            "revision": "b99aa811b4c1dd84cc6bccb8499c82c72098085a",
            "revisionTime": "2017-08-04T09:34:15Z"
        }
    ],
    "rootPath": "mytool"
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末装诡,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子践盼,更是在濱河造成了極大的恐慌鸦采,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件咕幻,死亡現(xiàn)場離奇詭異渔伯,居然都是意外死亡,警方通過查閱死者的電腦和手機肄程,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門锣吼,熙熙樓的掌柜王于貴愁眉苦臉地迎上來选浑,“玉大人,你說我怎么就攤上這事玄叠」磐剑” “怎么了?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵读恃,是天一觀的道長描函。 經(jīng)常有香客問我,道長狐粱,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任胆数,我火速辦了婚禮肌蜻,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘必尼。我一直安慰自己蒋搜,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布判莉。 她就那樣靜靜地躺著豆挽,像睡著了一般。 火紅的嫁衣襯著肌膚如雪券盅。 梳的紋絲不亂的頭發(fā)上帮哈,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天,我揣著相機與錄音锰镀,去河邊找鬼娘侍。 笑死,一個胖子當(dāng)著我的面吹牛泳炉,可吹牛的內(nèi)容都是我干的憾筏。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼花鹅,長吁一口氣:“原來是場噩夢啊……” “哼氧腰!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起刨肃,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤古拴,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后之景,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體斤富,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年锻狗,在試婚紗的時候發(fā)現(xiàn)自己被綠了满力。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片焕参。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖油额,靈堂內(nèi)的尸體忽然破棺而出叠纷,到底是詐尸還是另有隱情,我是刑警寧澤潦嘶,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布涩嚣,位于F島的核電站,受9級特大地震影響掂僵,放射性物質(zhì)發(fā)生泄漏航厚。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一锰蓬、第九天 我趴在偏房一處隱蔽的房頂上張望幔睬。 院中可真熱鬧,春花似錦芹扭、人聲如沸麻顶。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽辅肾。三九已至,卻和暖如春轮锥,著一層夾襖步出監(jiān)牢的瞬間矫钓,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工舍杜, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留份汗,地道東北人。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓蝴簇,卻偏偏與公主長得像杯活,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子熬词,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容

  • 1. 安裝 使用
    莫夏_b560閱讀 999評論 0 0
  • [TOC] 介紹 godep是解決包依賴的管理工具旁钧,目前最主流的一種,原理是掃描記錄版本控制的信息互拾,并在go命令前...
    木貓尾巴閱讀 17,620評論 0 7
  • 引言 Go 語言這兩年在語言排行榜上的上升勢頭非常猛歪今,Go 語言雖然是靜態(tài)編譯型語言,但是它卻擁有腳本化的語法颜矿,支...
    一縷殤流化隱半邊冰霜閱讀 33,487評論 11 90
  • 心碎成檸檬精 手機自由落體了啊啊啊啊啊 手機花屏了嚶嚶嚶 手機外屏沒事寄猩,內(nèi)屏彩虹了呀 我的媽T_T 哭哭 2.7點...
    云衣zxt閱讀 339評論 0 0
  • 梧桐兼翠綠,高天共蔚藍骑疆。 秋風(fēng)起鄱水田篇,落葉滿茶山替废! 有缺居偏隅,無朋空自談泊柬。 拆翼終歸短椎镣,振翅渡難關(guān)!
    逸塵居士閱讀 198評論 1 1