Go使用glide管理依赖库
安装
使用yum安装
$ sudo yum install glide
离线包安装
$ curl https://glide.sh/get | sh
或者
$ wget -c https://github.com/Masterminds/glide/releases/download/v0.12.3/glide-v0.12.3-linux-amd64.tar.gz
$ tar zxvf glide-v0.12.3-linux-amd64.tar.gz
$ mv ./linux-amd64/glide <PATH>
初始化工程
$ mkdir myapp
$ cd myapp
$ export GOPATH=`pwd`
$ /opt/glide/bin/glide init
初始化工程后,会生成一个glide.yaml文件,内容如下:
$ cat glide.yaml
package: .
import: []
安装依赖库
安装指定的库
$ glide get --all-dependencies -s -v github.com/go-redis/redis
...
$ cat glide.yaml
package: .
import:
- package: github.com/go-redis/redis
version: ^5.0.0
$ cat glide.lock
hash: b83ff10e7d57ded1279813a443c646c253c6313617d0a6ba5f0f7ca19bf561dd
updated: 2016-10-24T05:47:44.591801527-04:00
imports:
- name: github.com/go-redis/redis
version: 6f8957c5b7dece15d1ea5f592ec88f46ee2deffa
testImports: []
安装指定版本的库
$ glide get --all-dependencies -s -v github.com/go-redis/redis#5.0.0
$ cat glide.yaml
package: .
import:
- package: github.com/go-redis/redis
version: 5.0.0
$ cat glide.lock
hash: 7f8ea571efa3eae755284b25ef53a3ad08d78d0f02ec69cdda179add23959d08
updated: 2016-10-24T05:59:55.037552576-04:00
imports:
- name: github.com/go-redis/redis
version: 80cf5d1652d5590c35edc6c2dc1aa354790e3010
testImports: []
根据配置文件安装库
package: .
import:
- package: github.com/go-redis/redis
version: 5.0.0
然后使用下面的命令来安装库
$ glide install
安装完成后配置文件如下:
$ cat glide.yaml
package: .
import:
- package: github.com/go-redis/redis
version: 5.0.0
$ cat glide.lock
hash: 7f8ea571efa3eae755284b25ef53a3ad08d78d0f02ec69cdda179add23959d08
updated: 2016-10-24T05:59:55.037552576-04:00
imports:
- name: github.com/go-redis/redis
version: 80cf5d1652d5590c35edc6c2dc1aa354790e3010
testImports: []
转载请以链接形式标明本文链接
本文链接:http://www.jb51.cc/article/p-dgpaxpek-nx.html