This is a creation in Article, where the information may have evolved or changed.
GODEP is a management tool that resolves package dependencies
Installation
go get github.com/tools/godep
After a successful installation, there will be a GODEP executable binary in the bin directory of the Gopath, followed by the command to add the directory to the path directory.
Compiling and running
After the project is managed with GODEP, it is obviously not going to work with go run and go build when compiling and running the project, as the GO command goes directly to the Gopath directory to find a third-party library. Instead, the dependent libraries downloaded using GODEP are placed in the Godeps/workspace directory;
godep go build XXX
The GO command in GODEP is to add a shell to the previous GO command, and when the GODEP go is executed, the workspace directory of the current project is added to the Gopath variable;
GODEP Save
GODEP save copies the third-party libraries used in the project to the project's Godeps directory.
GODEP Save automatically scans all external dependent libraries (non-system libraries) of the import in the current directory's package, 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: the current or the package to be scanned can be compiled successfully: therefore all dependent packages should have been previously or go get or manual operation saved to the current Gopath path dependent packages must use a code management tool (such as Git, HG): This is because GODEP need to record revision
GODEP Restore
If there are only Godeps.json files in the downloaded project, and no third library is included, you can use the GODEP Restore command to get all the dependent libraries down to the Gopath src.
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.
Golang comes with package management tools
Bring your own tools: Go GetGo Get can download the dependent third-party library of this Gopath directory, in the code directly import the corresponding code base can be. Compared with GODEP, if the project refers to a third-party library is not included in the project, the installation of the project, for the third-party libraries need to use go get download, more trouble;
Note: Using GODEP restore may cause some libraries to fail to download; Compile error: Cmd/decode.go:16:2: Cannot find package "github.com/codislabs/redis-port/pkg/ Libs/atomic2 "In any of:
At this point for the error of the specific library and go get generally can download: Go get github.com/codislabs/redis-port/pkg/libs/atomic2
Commands supported by GODEP
save list and copy dependencies into Godepsgo run the go tool with saved dependenciesget download and install packages with specified dependenciespath print GOPATH for dependency coderestore check out listed dependency versions in GOPATHupdate update selected packages or the go versiondiff shows the diff between current and previously saved set of dependenciesversion show version info