Introduced
One problem that the early Golang were criticized by many developers was the management of the package. Golang 1.5 Release release, you can only solve this problem by setting up multiple Gopath, for example: both of my projects rely on Beego, but the a project relies on that Beego1.1
B project relies on Beego1.7
that I must set two gopath to differentiate , and when switching engineering, Gopath also have to switch, extremely painful. Finally finally in Golang 1.5 release began to support in addition to goroot and Gopath dependent query, that is vender
, so many big guy started to build wheels, build better should be dep
and glide
.
Protagonist appearances
Today's protagonist is dep
Golang's official Reliance Tool for managing and downloading engineering-dependent tools, the following is an official introduction
DEP is a prototype dependency management tool for Go. It requires Go 1.9 or newer to compile. DEP is safe for production use.
Installation
- MacOS
brew install dep
- Linux
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- Windows
go get -u github.com/golang/dep/cmd/dep
Windows has to compile itself and make sure to $GOPATH/bin
add it to the environment variable $PATH
Verify
Enter and return at the command line and the dep
following prompt will appear, indicating that the installation was successful.
Image.png
function Introduction
DEP Init
Image.png
Back up the current vender
, create a vender
directory and download all the dependent packages in the project, build Gopkg.lock
andGopkg.toml
The following is a description of the function of the two files, which is simply a Gopkg.toml
manifest file, which Gopkg.lock
is a checksum file. Try not to modify and avoid errors that cause two files to be unsynchronized.
A manifest-a file describing the current project ' s dependency requirements. In DEP, this is the gopkg.toml file. A lock-a file containing a transitively-complete, reproducible description of the dependency graph. In DEP, this is the Gopkg.lock file.
DEP status
Used to view the details and status of project dependencies, very clear.
Image.png
DEP ensure
Try to make sure that all dependent libraries are installed, and if they are not downloaded, they are equivalent to incremental updates to the dependent libraries.
DEP ensure add github.com/roaringbitmap/roaring@^1.0.1
Download add a new dependent library, and incrementally update the manifest file and verify the description file. is a library- github.com/RoaringBitmap/roaring
dependent package name, which 1.0.1
is the version number of the library.
Local cache
Of course, DEP does not download every time, it works like Mevan, it will take precedence in the local warehouse search, the local repository is not found on the network downloaded, and added to the local warehouse.
$GOPATH/pkg/dep/sources