Go dependency management tool-dep

  Dependency management tools, golang

Go dependency management tools

Go dependency management tool

Environmental requirements

  • Golang >= 1.9
  • Dep

Current version:

dep:
 version     : devel
 build date  : 
 git hash    : 
 go version  : go1.10
 go compiler : gc
 platform    : linux/amd64

Latest releaseForv0.4.1

Installation

go get -u github.com/golang/dep/cmd/dep

If$GOPATH/binabsentPATH, you need to convert the generateddepFile from$GOPATH/binMove to$GOBIANunder

Verification

$ dep
Dep is a tool for managing dependencies for Go projects

Usage: "dep [command]"

Commands:

  init     Set up a new Go project, or migrate an existing one
  status   Report the status of the project's dependencies
  ensure   Ensure a dependency is safely vendored in the project
  prune    Pruning is now performed automatically by dep ensure.
  version  Show the dep version information

Examples:
  dep init                               set up a new project
  dep ensure                             install the project's dependencies
  dep ensure -update                     update the locked versions of all dependencies
  dep ensure -add github.com/pkg/errors  add a dependency to the project

Use "dep help [command]" for more information about a command.

Initialization

Execute the initialization command at the root directory of the project.depDuring initialization, all dependent packages required by the application are analyzed to obtain a list of dependent packages

And generatevendorDirectory,Gopkg.tomlGopkg.lockFile

image

Default initialization

$ dep init -v

Download directly from the corresponding network resources

Priority initialization from $GOPATH

$ dep init -gopath -v

The command starts with$GOPATHFind the existing dependency package and download it from the corresponding network resource if it does not exist.

Gopkg.toml

This document is composed ofdep initGeneration, including managementdepStatement of rules for conduct

required = ["github.com/user/thing/cmd/thing"]

ignored = [
  "github.com/user/project/pkgX",
  "bitbucket.org/user/project/pkgA/pkgY"
]

[metadata]
key1 = "value that convey data to other systems"
system1-data = "value that is used by a system"
system2-data = "value that is used by another system"

[[constraint]]
  # Required: the root import path of the project being constrained.
  name = "github.com/user/project"
  # Recommended: the version constraint to enforce for the project.
  # Note that only one of "branch", "version" or "revision" can be specified.
  version = "1.0.0"
  branch = "master"
  revision = "abc123"

  # Optional: an alternate location (URL or import path) for the project's source.
  source = "https://github.com/myfork/package.git"

  # Optional: metadata about the constraint or override that could be used by other independent systems
  [metadata]
  key1 = "value that convey data to other systems"
  system1-data = "value that is used by a system"
  system2-data = "value that is used by another system"

Gopkg.lock

This document is composed ofdep ensureAnddep initGenerated, containing a complete snapshot of the project dependency graph, expressed as a series of[[project]]Section

# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.

[[projects]]
  branch = "master"
  name = "github.com/golang/protobuf"
  packages = [
    "jsonpb",
    "proto",
    "protoc-gen-go/descriptor",
    "ptypes",
    "ptypes/any",
    "ptypes/duration",
    "ptypes/struct",
    "ptypes/timestamp"
  ]
  revision = "bbd03ef6da3a115852eaf24c8a1c46aeb39aa175"

Common commands

dep ensure

From theGopkg.tomlAndGopkg.lockAnalyze the diagram in and obtain the required dependency packages

It is used to ensure that the local diagrams, locks and dependency package lists are completely consistent.

dep ensure -add

# 引入该依赖包的最新版本
dep ensure -add github.com/pkg/foo

# 引入具有特定约束(指定版本)的依赖包
dep ensure -add github.com/pkg/foo@^1.0.1

dep ensure -update

willGopkg.lockThe contract dependency in is updated toGopkg.tomlThe latest version allowed

Last

At presentdepIt is still in the official test stage, but has said that the production can be used safely.

If there is any problem, everyone can leave a message to discuss it.