This is a creation in Article, where the information may have evolved or changed.
Go Dependency Management tool
Go Dependency Management tool
Environmental requirements
Current version:
dep: version : devel build date : git hash : go version : go1.10 go compiler : gc platform : linux/amd64
Latest release
Forv0.4.1
Installation
go get -u github.com/golang/dep/cmd/dep
If $GOPATH/bin
not PATH
, you will need to move the resulting dep
file from $GOPATH/bin
$GOBIAN
the
Verify
$ depDep is a tool for managing dependencies for Go projectsUsage: "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 informationExamples: 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 projectUse "dep help [command]" for more information about a command.
Initialization
Executes initialization commands at the project root, dep
parses all dependent packages required by the application at initialization, and draws a list of dependent packages
and generate vendor
directories, Gopkg.toml
Gopkg.lock
files
Default initialization
$ dep init -v
Download directly from the corresponding network resource
Initialize from $gopath first
$ dep init -gopath -v
The command will be downloaded from the $GOPATH
corresponding network resource by looking for the existing dependency package, if it does not exist.
Gopkg.toml
The file is dep init
generated by dep
a rule declaration that contains administrative behavior
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's used by a syste M "System2-data =" value "used by another system" [[Constraint]] # required:the Root import path of the project Bei ng constrained. Name = "Github.com/user/project" # recommended:the version constraint to enforce for the project. # Note that only one of the "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 this could be used by other independent systems [metadata] Key1 = "value, convey data to other systems" System1-data = "value Used by a system "System2-data =" value, is used by anotheR system "
Gopkg.lock
The file consists dep ensure
dep init
of and generates a complete snapshot of the delivery of a project dependency graph, expressed as a series of [[project]]
sections
# 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
Parse the diagram from Gopkg.toml
and in the project and Gopkg.lock
get the required dependency packages
Used to ensure that local diagrams, locks, and dependent package manifests are fully consistent
DEP Ensure-add
# 引入该依赖包的最新版本dep ensure -add github.com/pkg/foo# 引入具有特定约束(指定版本)的依赖包dep ensure -add github.com/pkg/foo@^1.0.1
DEP Ensure-update
Gopkg.lock
Update the contract dependencies in to the Gopkg.toml
latest allowed version
At last
It is dep
still in the official pilot phase but has indicated that production is safe to use
If there is any problem, you can leave a message to discuss