glide使用

weixin_34405925發表於2016-07-11
github:

https://github.com/Masterminds/glide

document:

http://glide.readthedocs.io/en/stable/?badge=stable

golang環境設定
設定環境變數 使用vendor目錄
GO15VENDOREXPERIMENT=1
安裝
獲取
$ go get github.com/Masterminds/glide
進入目錄
$ cd github.com/Masterminds/glide
編譯
$ make build
$ go build -o glide -ldflags "-X main.version=v0.11.0" glide.go
使用
# 建立glide.yaml檔案 提示選擇N(選擇Y 是重新配置檔案需手動指定)
$ glide create
#開啟配置檔案
$ open glide.yaml                         
#使用glide獲取包會自動寫入glide.yaml檔案中
$ glide get github.com/Masterminds/cookoo
# 安裝glide.yaml所需的包
$ glide install
# 專案編譯
$ go build
# glide更新包
$ glide up                                

*注意

可以指定下載包的地址,版本號,下載方式
例如(golang包需要指定下載地址):

- package: golang.org/x/net/context
repo:    git@github.com:golang/net.git
vcs:     git

上述的編寫方式用空格做縮排,所有key對齊。

完整的配置檔案格式

package: github.com/Masterminds/glide
homepage: https://masterminds.github.io/glide
license: MIT
owners:
- name: Matt Butcher
email: technosophos@gmail.com
homepage: http://technosophos.com
- name: Matt Farina
email: matt@mattfarina.com
homepage: https://www.mattfarina.com
ignore:
- appengine
excludeDirs:
- node_modules
import:
- package: gopkg.in/yaml.v2
- package: github.com/Masterminds/vcs
version: ^1.2.0
repo:    git@github.com:Masterminds/vcs
vcs:     git
- package: github.com/codegangsta/cli
- package: github.com/Masterminds/semver
version: ^1.0.0
testImport:
- package: github.com/arschles/assert

版本號指定(version欄位)

=: equal (aliased to no operator)
!=: not equal
>: greater than
<: less than
>=: greater than or equal to
<=: less than or equal to

1.2 - 1.4.5 which is equivalent to >= 1.2, <= 1.4.5
2.3.4 - 4.5 which is equivalent to >= 2.3.4, <= 4.5
1.2.x is equivalent to >= 1.2.0, < 1.3.0

>= 1.2.x is equivalent to >= 1.2.0
<= 2.x is equivalent to < 3
* is equivalent to >= 0.0.0

~1.2.3 is equivalent to >= 1.2.3, < 1.3.0
~1 is equivalent to >= 1, < 2
~2.3 is equivalent to >= 2.3, < 2.4
~1.2.x is equivalent to >= 1.2.0, < 1.3.0
~1.x is equivalent to >= 1, < 2

^1.2.3 is equivalent to >= 1.2.3, < 2.0.0
^1.2.x is equivalent to >= 1.2.0, < 2.0.0
^2.3 is equivalent to >= 2.3, < 3
^2.x is equivalent to >= 2.0.0, < 3

'*'指定版本報錯,需要用'*'指定的可以不填寫

相關文章