Column address: Technical articles column
At the same time, you are also welcome to follow my wechat public account AlwaysBeta, more exciting content waiting for you.
Govendor is a go language dependency management tool.
Installation and initialization
Installation:
go get -u -v github.com/kardianos/govendor
Copy the code
Initialization:
# Setup your project.
cd "my project in GOPATH"
govendor init
# Add existing GOPATH files to vendor.
govendor add +external
Copy the code
Downloading dependency Packages
Here are three commands:
govendor fetch
: You can download not only your own packages, but also dependencies.govendor get
Copies dependencies into a “vendor” folder. Copies dependencies into a “vendor” folder.govendor add
: Add packages from $GOPATH;
To sum up, if you are downloading dependency packages, you must use GoVendor Fetch.
Govendor fetch github.com/gin-gonic/[email protected]Copy only the contents of gin/, not its subdirectoriesgovendor fetch github.com/gin-gonic/gin/... @ v1.2The gin/ directory and all its subdirectories are available
Copy the code
@v1.2 is a revision with git tag v1.2, which is useful.
Another problem we may encounter is that sometimes we use third-party dependency packages and there are bugs. After fixing them, we can do this if we want to use our own repository:
govendor get 'github.com/go-sql-driver/mysql::github.com/yongxinz/go-mysql'
Copy the code
There is a small problem with github.com/go-sql-driver/mysql in the original warehouse. Expect to use the self-fixed github.com/yongxinz/go-mysql at this time.
Version management
Don’t mention the entire vendor/ directory to the Git repository. Just submit the vendor/vendor.json file.
When we have pulled the code and need to install the dependencies, we simply need to execute the following command.
govendor sync
Copy the code
.gitignore file, focus on the last two lines:
# Created by https://www.gitignore.io/api/go
### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
### Go Patch ###/vendor/ ! /vendor/vendor.jsonCopy the code
So, the general development process goes like this: If you are creating a new project, install goVendor and initialize it, and then install dependencies through GoVendor. If it is an existing project, pull down the version library, install goVendor, and then run the synchronization command.
Other commands
Govendor status: Displays the current package status
Govendor List +e: View packages that the current project depends on but are not added to the vendor
Govendor add +e: adds a dependent package. Packages that exist in vendor.json but do not exist in the vendor directory (that is, the goVendor status display is missing) will also be added again
Govendor remove +u: Removes packages that are under the vendor but are not dependent on
In practice, some packages are common to the team. This subcontract usually has its own separate project and has been added to $GOPATH by us, so it may not need to be added to the vendor of the current project.
To add dependencies to a list, use list-no-status +e to list dependencies, then use grep to filter dependencies, and then use add to add dependencies:
govendor list -no-status +e | grep -v 'myteam/common' | xargs govendor add
Copy the code
Related documents: github.com/kardianos/g… www.orztu.com/post/using-… Linkscue.com/2018/08/09/…