govendor is a Go package dependency management command line tool based on the
vendor
mechanism. Non-intrusive integration with native vendors, and also supports migration from other dependency management tools. It can easily realize the development and management of different versions of the same package in different projects without mutual intrusion.
At the beginning, Go did not provide a more appropriate package management tool. The vendor feature is provided starting from version 1.5, but the environment variableGO15VENDOREXPERIMENT=1
needs to be set manually.
When executing thego build
orgo run
command, the package will be searched in the following order:
When version 1.6 was released, the value of this environment variable was set to 1 by default. This value can be viewed using thego env
command.
When version 1.7 was released, this environment variable was removed and thevendor
feature was enabled by default.
package
that does not containmain
) should not store external files in its own version control The packages are in thevendor
directory, unless there is a special reason and you know why you want to do this.In an application, (package
containingmain
), it is recommended that there is only onevendor
directory, and it is located in the code base level directory.
Related tutorials:go video tutorial
govendor is a directory based onvendor
Mechanical package management tool.
$GOPATH
to thevendor
directory of the projectvendor/vendor.json
for package and version management, which is similar to PHP'sComposer
govendor add/ The update
command copies the dependent package from$GOPATH
vendor/*/
file is ignored, you can usegovendor sync
to restore the dependency Packagegovendor fetch
to add or update dependent packagesgovendor migrate
from othervendor
package management tools One-click migration togovendor
:
$GOPATH/src
directoryset GO15VENDOREXPERIMENT=1
go get -u github.com/kardianos/govendor
For convenience and quick usegovendor
, it is recommended to add$GOPATH/bin
to PATH. Linux/macOS settings are as follows:
export PATH="$GOPATH/bin:$PATH"
Execute the following command in the project root directory forvendor
Initialization:
govendor init
In the project root directory, that is Thevendor
directory andvendor.json
file will be automatically generated. At this time, the content of thevendor.json
file is:
{ "comment": "", "ignore": "test", "package": [], "rootPath": "govendor-example" }
$GOPATH
Copy the package to thevendor
directorygovendor add +external
$GOPATH
govendor add gopkg.in/yaml.v2
govendor list
e github.com/gin-contrib/sse e github.com/gin-gonic/gin e github.com/gin-gonic/gin/binding e github.com/gin-gonic/gin/internal/json e github.com/gin-gonic/gin/render e github.com/golang/protobuf/proto e github.com/mattn/go-isatty e github.com/ugorji/go/codec e gopkg.in/go-playground/validator.v8 e gopkg.in/yaml.v2 pl govendor-example m github.com/json-iterator/go m golang.org/x/sys/unix
govendor list -v fmt
s fmt ├── e github.com/gin-contrib/sse ├── e github.com/gin-gonic/gin ├── e github.com/gin-gonic/gin/render ├── e github.com/golang/protobuf/proto ├── e github.com/ugorji/go/codec ├── e gopkg.in/go-playground/validator.v8 ├── e gopkg.in/yaml.v2 └── pl govendor-example
$GOPATH
)govendor fetch golang.org/x/net/context
govendor fetch golang.org/x/net/context@a4bbce9fcae005b22ae5443f6af064d80a6f5a55 govendor fetch golang.org/x/net/context@v1 # Get latest v1.*.* tag or branch. govendor fetch golang.org/x/net/context@=v1 # Get the tag or branch named "v1".
vendor
directory)govendor fmt +local
govendor install +local
govendor test +local
vendor
packagesgovendor install +vendor,^program
vendor
directory (including$GOPATH
existing or non-existing packages)govendor fetch +out
vendor
directory, but I want to update it from$GOPATH
govendor update +vendor
$GOPATH
Now I want to update the modified and uncommitted package tovendor
govendor update -uncommitted
govendor fetch github.com/normal/pkg::github.com/myfork/pkg
will now pull the code frommyfork
instead ofnormal
.
vendor.json
records the dependency package information, how to pull updatesgovendor sync
each For detailed usage of subcommands, you can check how the source code package is implemented throughgovendor COMMAND -h
or readgithub.com/kardianos/govendor/context
.
Subcommand | Function |
---|---|
Create | vendordirectory and vendor.jsonfile |
List & filter dependent packages and their status | |
Copy the package from | $GOPATHto the project vendordirectory |
Update dependency packages to project | vendorfrom $GOPATHDirectory |
from | vendorDirectory to remove dependent packages |
List all missing, expired and modified packages | |
Add or update packages from the remote repository to the project | vendordirectory (will not be stored in $GOPATH) |
Pull matching packages to the | vendordirectory based on vendor.json#migrate | One-click migration from other package management tools based on
get | is similar to
|
$GOPATH | , and then copy the dependent package to thevendordirectory
license | List all dependencies The LICENSE
shell | of the package can run multiple |
govendor Status Parameter |
local | ||
---|---|---|
external | e | |
GOPATH | but not in the projectvendor | directory
vendor | v
vendor | directorystd | s
|
excluded | x | |
unused | u | |
vendor | directory, but not referenced in the project## missing m |
|
program | p | |
outside | ||
external missing | all
|
|
list | 、
、remove
、fetch
Go modules
Pudaxiben What's interesting is that starting from Go version 1.11, the official has built in more powerful Go modules to unify the chaotic situation of Go package dependency management for many years (the dep tool previously launched by Go officials was almost stillborn), and will be released in 1.13 It is officially enabled by default in this version.
It has been favored and strongly recommended by the community, and it is recommended that new projects use Go modules.
The above is the detailed content of A brief discussion on govendor, the Go package dependency management tool. For more information, please follow other related articles on the PHP Chinese website!