glide is golang project development is particularly important software, without it, the project golang probably not be published.
Why use glide
Usually we developed Go project, the use of third-party packages when they are used directly go get to acquire third-party packages, but go get acquired to develop the package is a branch of the project, we developed when it touches can not very concerned about. But if the production environment, directly go get a very risky, because we all know, develop a development branch, defenders will push new code to the development branch, if we use go get it, probably every time we publish version get to third-party code is inconsistent, so the project will have a particularly large risk. We certainly hope to go get a third-party package to our project, they can set up a stable version to use. But go get it unable to meet the most common requirements. Then, glide it turned out.
How to use glide
Installation glide
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
After the complete installation was successful test
glide -h
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.
The above message appears on the screen indicate the installation was successful.
Introduce a few more usually develop a few commands, and these commands to master the project development on the basic question of nothing.
glide init --初始化项目,生成glide.yaml
glide install --安装第三方包
glide up --更新第三方包
For chestnuts
Be UUID use cases
first 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)
}
RUN
10c2b95f-b7c2-45f3-b5a3-a69020b9a7f7
Process finished with exit code 0
Then enter into the project directory
glide init
会生成一个包含UUID包的yaml 文件
package: test
import:
- package: github.com/satori/go.uuid
We give this package plus the version number
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 particularly useful, especially useful now.