golang包管理工具——glide

1. glide安装

glide是Go的包管理工具。支持语义化版本,支持Git、Svn等,支持Go工具链,支持vendor目录,支持从Godep、GB、GPM、Gom倒入,支持私有的Repos和Forks。

glide 的安装很简单,mac环境下直接 brew install glide 就可以的。装完之后,那么直接使用 glide init 或者 glide create 即可,然后你就会发现你的目录下会有一个新的 glide.yaml 的 YAML 文件,里面描述了 package 的信息,但是只是依赖信息,并没有版本信息。

2. 初始化

glide init (参考输出如下,执行后生成:glide.yaml 文件)

 1 [INFO]    Generating a YAML configuration file and guessing the dependencies
 2 [INFO]    Attempting to import from other package managers (use --skip-import to skip)
 3 [INFO]    Scanning code to look for dependencies
 4 [INFO]    --> Found reference to github.com/astaxie/beego
 5 [INFO]    --> Adding sub-package cache to github.com/astaxie/beego
 6 [INFO]    --> Adding sub-package context to github.com/astaxie/beego
 7 [INFO]    --> Adding sub-package httplib to github.com/astaxie/beego
 8 [INFO]    --> Adding sub-package logs to github.com/astaxie/beego
 9 [INFO]    --> Adding sub-package orm to github.com/astaxie/beego
10 [INFO]    --> Found reference to github.com/go-sql-driver/mysql
11 [INFO]    --> Found reference to github.com/qiniu/api.v7/auth/qbox
12 [INFO]    --> Adding sub-package storage to github.com/qiniu/api.v7
13 [INFO]    --> Found reference to github.com/russross/blackfriday
14 [INFO]    --> Found reference to github.com/xormplus/xorm
15 [INFO]    --> Found test reference to github.com/smartystreets/goconvey/convey
16 [INFO]    Writing configuration file (glide.yaml)
17 [INFO]    Would you like Glide to help you find ways to improve your glide.yaml configuration?
18 [INFO]    If you want to revisit this step you can use the config-wizard command at any time.
19 [INFO]    Yes (Y) or No (N)?
20 Y
21 [INFO]    Looking for dependencies to make suggestions on
22 [INFO]    --> Scanning for dependencies not using version ranges
23 [INFO]    --> Scanning for dependencies using commit ids
24 [INFO]    Gathering information on each dependency
25 [INFO]    --> This may take a moment. Especially on a codebase with many dependencies
26 [INFO]    --> Gathering release information for dependencies
27 [INFO]    --> Looking for dependency imports where versions are commit ids
28 
29 [INFO]    Here are some suggestions...
30 [INFO]    The package github.com/astaxie/beego appears to have Semantic Version releases (http://semver.org). 
31 [INFO]    The latest release is v1.9.2. You are currently not using a release. Would you like
32 [INFO]    to use this release? Yes (Y) or No (N)
33 Y
34 [INFO]    Would you like to remember the previous decision and apply it to future
35 [INFO]    dependencies? Yes (Y) or No (N)
36 Y
37 [INFO]    Updating github.com/astaxie/beego to use the release v1.9.2 instead of no release
38 [INFO]    The package github.com/astaxie/beego appears to use semantic versions (http://semver.org).
39 [INFO]    Would you like to track the latest minor or patch releases (major.minor.patch)?
40 [INFO]    The choices are:
41 [INFO]     - Tracking minor version releases would use '>= 1.9.2, < 2.0.0' ('^1.9.2')
42 [INFO]     - Tracking patch version releases would use '>= 1.9.2, < 1.10.0' ('~1.9.2')
43 [INFO]     - Skip using ranges
44 [INFO]    For more information on Glide versions and ranges see https://glide.sh/docs/versions
45 [INFO]    Minor (M), Patch (P), or Skip Ranges (S)?
46 P
47 [INFO]    Would you like to remember the previous decision and apply it to future
48 [INFO]    dependencies? Yes (Y) or No (N)
49 Y
50 [INFO]    Updating github.com/astaxie/beego to use the range ~1.9.2 instead of commit id v1.9.2
51 [INFO]    Updating github.com/go-sql-driver/mysql to use the release v1.3 instead of no release
52 [INFO]    Updating github.com/go-sql-driver/mysql to use the range ~1.3.0 instead of commit id v1.3
53 [INFO]    Updating github.com/qiniu/api.v7 to use the release v7.2.3 instead of no release
54 [INFO]    Updating github.com/qiniu/api.v7 to use the range ~7.2.3 instead of commit id v7.2.3
55 [INFO]    Updating github.com/russross/blackfriday to use the release v2.0.0 instead of no release
56 [INFO]    Updating github.com/russross/blackfriday to use the range ~2.0.0 instead of commit id v2.0.0
57 [INFO]    Updating github.com/smartystreets/goconvey to use the release 1.6.3 instead of no release
58 [INFO]    Updating github.com/smartystreets/goconvey to use the range ~1.6.3 instead of commit id 1.6.3
59 [INFO]    Configuration changes have been made. Would you like to write these
60 [INFO]    changes to your configuration file? Yes (Y) or No (N)
61 Y
62 [INFO]    Writing updates to configuration file (glide.yaml)
63 [INFO]    You can now edit the glide.yaml file.:
64 [INFO]    --> For more information on versions and ranges see https://glide.sh/docs/versions/
65 [INFO]    --> For details on additional metadata see https://glide.sh/docs/glide.yaml/
View Code

3. 安装依赖

glide install (会生成glide.lock文件,锁定安装包的版本)

4. glide报错及解决集:

Q:[ERROR] Error scanning google.golang.org/appengine/cloudsql: cannot find package "." in: /Users/hezhixiong/.glide/cache/src/https-google.golang.org-appengine-cloudsql
A: 在glide.yaml最下方添加如下:
- package: google.golang.org/appengine
  repo: https://github.com/golang/appengine
  vcs: git
  subpackages:
  - cloudsql

Q: [ERROR]    Update failed for golang.org/x/crypto: Cannot detect VCS
A: 在glide.yaml最下方添加如下:
- package: golang.org/x/crypto
  repo: https://github.com/golang/crypto

Q: [ERROR]    Failed to set version on golang.org/x/sys/unix to : Cannot detect VCS
A: 在glide.yaml最下方添加如下:
- package: golang.org/x/sys
  repo: https://github.com/golang/sys
  vcs: git
  subpackages:
  - unix
View Code

5. 参考资料

(1)glide文档:https://glidedocs.readthedocs.io/zh/latest/

posted @ 2018-11-26 15:16  hezhixiong  阅读(556)  评论(0编辑  收藏  举报