This is a creation in Article, where the information may have evolved or changed.
[TOC]
Introduced
GODEP is the management tool to solve the package dependency, the most mainstream one, the principle is to scan the record version control information, and the go command before the shell to achieve dependency management
GODEP recommended for use after Golang 1.6
GODEP depends on vendor specific view https://stackoverflow.com/questions/37237036/how-should-i-use-vendor-in-go-1-6
Please do vendor management
Installation
Https://github.com/tools/godep
go get -u -v github.com/tools/godep
After a successful installation, $GOPATH的bin目录 there will be a GODEP executable binaries, followed by the following commands are used, it is recommended that this directory is added to the Global environment variables
Package Management uses GODEP
The following commands are run at the root of the project
Pull dependent restore for development
godep restore
It is recommended that the development process use this command to synchronize dependent libraries
If you have only godeps.json files in the downloaded project, and you do not include a third library, you can use the GODEP Restore command to bring all dependent libraries down $GOPATH\src to the development
When GODEP restore executes, GODEP follows the Godeps/Godeps.json inside list, then executes go get -d -v to download the corresponding dependency package to the Gopath path
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 My.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/my.io directory, and then git clone
Check out dependent save
godep save
If the development relies on using a three-party library and needs to be fixed using a version, please submit the Godeps`和 Vendor ' folder fully
The lower version of GODEP is generated Godeps/_workspace , the recommended upgrade
Two elements are required for successful execution of GODEP Save:
- The current or the package that needs to be scanned can be compiled successfully: so all dependent packages should be saved in advance or go get or manual operation to save 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
This command is used for compiling builds, and the three-party build tool requires additional configuration of the build parameters
GODEP Compile Run Build
After the project is managed with GODEP, it is obviously not possible to compile and run the project with Go run and go build
Because the GO command is to go directly to the Gopath directory to find a third-party library, and after 1.6 support for the vendor way to compile, and use the GODEP download of the dependent library placed in the Godeps/workspace directory, but does not affect the continued use of dependent Gopath directory, So it doesn't conflict with the three-party tool itself.
therefore use
godep go build XXX
The Go command in GODEP, which adds a shell to the previous GO command, adds the workspace directory of the current project to the Gopath variable when the GODEP go is executed.
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.
And in 使用IDE时 , can be vendor added to the Gopath implementation code jump and compile functions, more convenient
GODEP Other Commands
save list and copy dependencies into Godeps go run the go tool with saved dependencies get download and install packages with specified dependencies path print GOPATH for dependency code restore check out listed dependency versions in GOPATH update update selected packages or the go version diff shows the diff between current and previously saved set of dependencies version show version info