Glide Golang Package Management

Golang's package management is messy, and various tools have emerged, each showing its magic. After using it for a few times, I found that Glide is relatively easy to use. Vender is used for management. The versions of multiple development environments do not conflict. The functions are powerful and the configuration files are simple enough.

initialization

An existing project wants to introduce glide for management

→ glide create

At this time, Glide will scan all the files in the project and analyze the dependencies, and then provide options such as tracking Minor or tracking Patch. Finally, Glide generates a basic configuration file glide.yaml.

The content in my test project is as follows:

package: reposkeeper.net/awesomeTestProject
import:
- package: golang.org/x/net
- package: google.golang.org/grpc
  version: ^1.9.2

Configuration file parsing

Glide uses yaml as the format for configuration files. The top-level configurable options have the following options:

  • package indicates the location of this project in GOPATH
  • homepage represents the details page of this project
  • license indicates the license used by the project
  • owners indicates the owner of the project, you can fill in multiple people
  • ignore Indicates the package to be ignored when importing (this is more commonly used in actual use to ignore some packages that do not meet the package management rules)
  • excludeDirs indicates the directories that Glide ignores when scanning
  • import represents a list of dependent packages
  • testImport represents the dependency package in the test, and its format is the same as import

Among the above, the more important and commonly used are import, ignore, excludeDirsthese three. Let's talk about it in detail.

import

import indicates the list of packages to be imported. For the configuration method of the example, see the following:

import:
  - package: github.com/Masterminds/vcs
    version: ^1.2.0
    repo:    [email protected]:Masterminds/vcs
    vcs:     git
  - package: golang.org/x/net
    subpackages:
    - context
  • package represents the name of the package to import
  • version indicates the version of the package, which can be version, version range, branch, tag, commit id
  • repo If the package name is not a repository address or belongs to a private repository, Glide will extract the package here
  • vcs represents the vcs used, such as: git, hg, svn, etc.
  • os can be specified to filter a specific operating system, the content is the same as GOOS
  • arch can be specified to filter a specific architecture, the content is the same as GOARCH
  • subpackages means to import only the packages that are used in one repository

Complete configuration example

package: github.com/Masterminds/glide
homepage: https://masterminds.github.io/glide
license: MIT
owners:
- name: Matt Butcher
  email: [email protected]
  homepage: http://technosophos.com
- name: Matt Farina
  email: [email protected]
  homepage: https://www.mattfarina.com
ignore:
- appengine
excludeDirs:
- node_modules
import:
- package: gopkg.in/yaml.v2
- package: github.com/Masterminds/vcs
  version: ^1.2.0
  repo:    [email protected]:Masterminds/vcs
  vcs:     git
- package: github.com/codegangsta/cli
  version: f89effe81c1ece9c5b0fda359ebd9cf65f169a51
- package: github.com/Masterminds/semver
  version: ^1.0.0
testImport:
- package: github.com/arschles/assert

Common operations

  • glide get [package name] Download a package to the vendor of the project and write it into the configuration file
  • glide up upgrades all packages
  • glide install installs all dependencies

END

The configuration and operation are relatively simple. In daily use, there will always be problems with the package being dropped by the wall. However, as a technician, scientific Internet access is a basic ability, and a proxy is enough.


Please indicate the author and source ( reposkeeper ) for reprinting, please do not use for any commercial purposes!

Follow the WeChat public account to get the push of new articles!
qrcode

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324825144&siteId=291194637