govendor依賴包管理

吳龍輝發表於2018-07-18

1.govendor簡介

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

常用的依賴包管理工具有godepgovendor等,在Golang1.5之後,Go提供了 GO15VENDOREXPERIMENT環境變數(Go 1.6版本預設開啟該環境變數),用於將go build時的應用路徑搜尋調整成為 當前專案目錄/vendor 目錄方式。通過這種形式,我們可以實現類似於 godep 方式的專案依賴管理。

 

2.govendor安裝

#v1.0.9

wget http://blob.wae.haplat.net/golang/govendor-v1.0.9.linux-amd64.tar.gz

tar zxvf govendor-v1.0.9.linux-amd64.tar.gz

rm /usr/bin/govendor && mv govendor /usr/bin

 

3.governdor使用

初始化

#進入到專案目錄

cd /path/to/your/project

 

#初始化vendor目錄

govendor init

 

 

#將GOPATH中本工程使用到的依賴包自動移動到vendor目錄中

#說明:如果本地GOPATH沒有依賴包,先go get相應的依賴包

govendor add +external

或使用縮寫: govendor add +e

 

新增/更新依賴包 github拉取

# Update a package to latest, given any prior version constraint

govendor fetch golang.org/x/net/context

 

 

#使用HTTP協議

govendor fetch -insecure [url]

 

# Specify a specific version or revision to fetch

govendor fetch golang.org/x/net/context@a4bbce9fcae005b22ae5443f6af064d80a6f5a55

govendor fetch golang.org/x/net/context@v1   # Get latest v1.*.* tag or branch.

govendor fetch golang.org/x/net/context@=v1  # Get the tag or branch named "v1".

 

更新/新增依賴包  本地GOPATH拷貝

# Update packages from $GOPATH.

govendor update golang.org/x/net/context

刪除依賴包

govendor remove [pkg]

 

參考

相關文章