Golang does not officially recommend the best package management solution. In the 1.5 era, the official package management design was introduced and the vendor directory was added to support local package management dependencies. Godep, GV, GVT, Glide, GoVendor, etc.
Here’s a quick look at one I used in my project — Govendor. The tool copies external packages dependent on the project to the vendor directory under the project, and records the version of the dependent package through the vendor.json file, which facilitates users to use relatively stable dependencies. For GoVendor, there are several types of dependency packages:
state | State of abbreviation | meaning |
---|---|---|
+local | l | Local packages, the package organization of the project itself |
+external | e | External packages, which are managed by $GOPATH but not in the vendor directory |
+vendor | v | It is managed by govendor, that is, in the vendor directory |
+std | s | Packages in the standard library |
+unused | u | Unused packages that are in the vendor directory but not used by the project |
+missing | m | The code referenced the dependency package, but the package was not found |
+program | p | Main package, meaning it can be compiled as an execution file |
+outside | External packages and missing packages | |
+all | All of the packages |
Installation
go get -u github.com/kardianos/govendor
Copy the code
Run the govendor command. If the following information is displayed, the installation is successful.
➜ ~ govendor
govendor (v1.0.8): record dependencies and copy into vendor folder
-govendor-licenses Show govendor's licenses. -version Show govendor version ... .Copy the code
** Warning: ** Need to add $GOPATH /bin/to PATH.
Quickstart
# Setup your project.
cd "my project in GOPATH"
The vendor directory will appear under project
govendor init
# Add existing GOPATH files to vendor.
govendor add +external
# View your work.
govendor list
# Look at what is using a package
govendor list -v fmt
# Specify a specific version or revision to fetch
govendor fetch golang.org/x/net/context@a4bbce9fcae005b22ae5443f6af064d80a6f5a55
# Get latest v1.*.* tag or branch.
govendor fetch golang.org/x/net/context@v1
# Get the tag or branch named "v1".
govendor fetch golang.org/x/net/context@=v1
# Update a package to latest, given any prior version constraint
govendor fetch golang.org/x/net/context
# Format your repository only
govendor fmt +local
# Build everything in your repository only
govendor install +local
# Test your repository only
govendor test +local
Copy the code
Sub-commands
Init Create vendor folder and vendor.json file list list of existing dependency packages add from$GOPATHAdd dependency packages to vendor.json update from$GOPATHUpgrade dependencies remove Remove dependencies from vendor folder Status Lists locally lost, expired, and modified package fetch Add new ones from remote libraries, Or update dependency packages in vendor files sync Pull packages into vendor Folder from remote repository with Revisions Move packages From a legacy tool to the vendor folder with metadata. Get However, dependent packages are copied to the Vendor directory License List Discovered Licensesfor the given status or import paths.
shell Run a "shell" to make multiple sub-commands more efficient for large projects.
go tool commands that are wrapped:
`+<status>` package selection may be used with them
fmt, build, install, clean, test, vet, generate, tool
Copy the code
Warning:
-
The project must be within a $GOPATH/src.
-
If using go1.5, ensure you set GO15VENDOREXPERIMENT=1.
reference
-
govendor github
-
Go relies on the management tool govendor
source
This article is from: Segmentfault
Thanks to the author: Happen
Go dependency management -govendor