glide 是golang项目开发中是特别重要的软件,没有它,golang的项目可能都没法发布。git
平时咱们开发Go项目的时候,使用第三方的包的时候都直接使用go get 去获取第三方的包,可是go get获取到的包是项目的develop分支,咱们开发的时候却是能够不怎么关注。可是若是到了生产环境,直接使用go get 是有很大风险的,由于,众所周知,develop是开发分支,维护者会把新的代码push到开发分支,若是咱们使用go get的话,可能咱们每次发布版本获取到的第三方代码都是不一致的,这样项目就会有特别大的风险。咱们确定但愿go get 第三方包到咱们项目中的时候,能够设置一个稳定的版原本使用。可是go get却没法知足这个最广泛的要求。而后,glide就横空出世了。github
安装glidegolang
mac系统或者Linux系统安装 curl https://glide.sh/get | sh Mac也可brew安装 brew install glide Ubuntu也能够apt-get安装 sudo add-apt-repository ppa:masterminds/glide && sudo apt-get update sudo apt-get install glide
完整以后测试下是否安装成功
glide -hcurl
NAME: glide - Vendor Package Management for your Go projects. Each project should have a 'glide.yaml' file in the project directory. Files look something like this: package: github.com/Masterminds/glide imports: - package: github.com/Masterminds/cookoo version: 1.1.0 - package: github.com/kylelemons/go-gypsy subpackages: - yaml For more details on the 'glide.yaml' files see the documentation at https://glide.sh/docs/glide.yaml USAGE: glide [global options] command [command options] [arguments...] VERSION: v0.13.2 COMMANDS: create, init Initialize a new project, creating a glide.yaml file config-wizard, cw Wizard that makes optional suggestions to improve config in a glide.yaml file. get Install one or more packages into `vendor/` and add dependency to glide.yaml.
出现上面的提示信息界面就表示安装成功了。
介绍几个平时开发用的比较多的几个命令,掌握了这几个命令项目开发就基本没啥问题了。ide
glide init --初始化项目,生成glide.yaml glide install --安装第三方包 glide up --更新第三方包
作个UUID使用案例
首先 go get github.com/satori/go.uuid测试
package main import ( "fmt" uuid2 "github.com/satori/go.uuid" ) func main() { uuid,_ := uuid2.NewV4() fmt.Println(uuid) }
运行下ui
10c2b95f-b7c2-45f3-b5a3-a69020b9a7f7 Process finished with exit code 0
而后进入到项目目录this
glide init 会生成一个包含UUID包的yaml 文件 package: test import: - package: github.com/satori/go.uuid
咱们给这个包加下版本号url
package: test import: - package: github.com/satori/go.uuid - version: 1.2.0 而后执行 glide install 显示里面有设置版本号的信息 [INFO] --> Fetching updates for github.com/satori/go.uuid [INFO] --> Setting version for github.com/satori/go.uuid to v1.2.0. 咱们看到在项目包里面生成一个 vendor的文件夹,vendor里面有个uuid 的包 vendor/github.com/satori/go.uuid,之后经过glide管理的包文件就在vendor里面。 若是咱们想把 version: 1.2.0 该为 version: 1.1.0.修改yaml文件的版本号,而后执行 glide up [INFO] --> Fetching updates for github.com/satori/go.uuid [INFO] --> Setting version for github.com/satori/go.uuid to v1.1.0. vendor里面的版本就切换到了v1.1.0
glide 特别好用,特别实用吧。code
详细的使用能够看官方的文档
https://github.com/Masterminds/glide