This is a creation in Article, where the information may have evolved or changed.
GODEP is currently golang the mainstream package management tool, a lot of go language-based projects such as Docker, CoreOS, kubernetes, etc. are using GODEP to solve project package dependencies and versioning issues. As a command-line tool, GODEP is simple, common basic GODEP Save and GODEP restore two commands are enough, so the general novice with official instructions can quickly get started. But there are a few small questions that are often confusing, and here are some notes and explanations:
GODEP the mechanism of Save
Without specifying a package name, GODEP automatically scans all external dependent libraries (non-system libraries) for import in the package that the current directory belongs to, and see if they belong to a code management tool (such as GIT,HG). If so, record the library fetch path and the current corresponding revision (commit ID) to Godeps.json under the current directory godeps, and copy the code without the Code management information (such as the. git directory) to the godeps/_workspace/ SRC, used to fix the path of a dependent package when commands such as the subsequent GODEP go build are executed.
Therefore, the successful execution of GODEP save requires two elements:
Current or scanned packages can be compiled successfully: therefore all dependent packages should be saved in advance or go get or manual operation to the current Gopath path
A dependency package must use a code management tool (such as GIT,HG): This is because GODEP needs to be logged revision
Mechanism of GODEP Restore
When GODEP restore executes, GODEP will follow the Godeps/godeps.json list, followed by Go get-d-V to download the corresponding dependency package to the Gopath path, so If one of the original dependent package save paths (relative paths under Gopath) is inconsistent with the download URL path, such as Kuberbetes on GitHub, the path is github.com/kubernetes, The import in the code is K8s.io, which results in the inability to download successfully, that is, GODEP restore is unsuccessful. This can only be done manually, such as manually creating the $gopath/k8s.io directory and then git clone.
The role of the Godeps directory
GODEP Save GODEP Copies all the dependent package code from the Gopath path to the Godeps directory and removes the Code management directory. This use is mainly to support the GODEP go tool of a series of operations, especially git clone the code base down, usually directly with GODEP go install xxx can be compiled, to a certain extent, to alleviate the Golang more stringent code path and package management problems. In the development of using the IDE, you can also add godeps/_workspace to the Gopath to implement code jump and compile functions, and more convenient. So this design is actually the essence of the GODEP tool.