Experience of using glide in go package management

Time:2020-10-6

Glide is a package management tool of go language https://glide.sh/ , GitHub address: https://github.com/Masterminds/glide 。 Of course, starting with go 1.13, the module pattern has become the default mode for all development. For information about go modules, please read the go official blog: using go modules

Here are some of glide’s experiences:

Generally use glide install, which will read the configuration file glide.lock To ensure that the dependency packages used in each build are the same and will not be upgraded casually.

Running glide up will automatically update glide.lock In the production environment, there are certain risks. For example, the latest version is not compatible with the development version, resulting in construction or running errors. Therefore, we generally use glide install.

The most powerful command is glide up, because in addition to parsing glide.yaml You will also walk through the dependency tree in the code and download it to the vendor directory.

glide.yaml For example, notice that the version in the file can be a branch name, a tag name, and so on.

package: github.com/foo/bar
import:
- package: git.apache.org/thrift.git
  version: =0.9.2
  subpackages:
  - lib/go/thrift
- package: github.com/bouk/monkey
  version: ^1.0.1

glide.lock Examples

hash: ed07eda8c92ac4df03a9b1fca70d6dac1d94430d1ebfa5011ca8c37eaec1173f
updated: 2020-02-25T15:56:03.200606621+08:00
imports:
- name: git.apache.org/thrift.git
  version: 591e20f9636c37527a70dc03598218c3468a0eff
  subpackages:
  - lib/go/thrift
- name: github.com/bouk/monkey
  version: bdf6dea004c6fd1cdf4b25da8ad45a606c09409a

be carefulglide.lockThe version in the file is git commit hashgithub.com/bouk/monkeyFor example,version: bdf6dea004c6fd1cdf4b25da8ad45a606c09409aIndicates the submission as follows:

$ git show bdf6dea004c6fd1cdf4b25da8ad45a606c09409a -n 1

commit bdf6dea004c6fd1cdf4b25da8ad45a606c09409a (tag: v1.0.1)
Merge: 5df1f20 58750f3
Author: Bouke van der Bijl 
Date:   Tue Aug 21 14:10:00 2018 +0200

    Merge pull request #20 from bouk/canonical

    Add canonical import path