govendor is a dependency manager for Go. Go get gets you pretty far when it comes to installing dependencies at first, but when you want to deploy your project or when you want to pin the right version of your dependency it’s not necessarily appropriate to use.
With govendor you can, like with
npm or other tools specify which version of your dependency your project uses, which is a huge benefit for systems that are required to be somewhat stable.
As usual, make sure your
GOPATH and similar are set correctly. Next step is to install govendor with
go get -u github.com/kardianos/govendor
To test if the installation succeed, open a terminal and type
govendor. If the output is not a long list of options, but a "command not found", you should have a look at your
.bashrc and see if your GOPATH is set correctly.
Using Govendor with for your Go Dependencies
In order to list all the packages and versions of go packages you are currently using, you can simply run
Which will produce an output with something like:
$YOURPACKAGE probably is the name of your directory.
e as a prefix means that all of these dependencies are external and not pinned to your project yet.
govendor add +external
Will add them to your dependency file. When you list your dependencies again will now start with a
v instead of an
vendor.json can be used to install the correct versions using:
Will install the packages at the right versions that are stated in your
vendor/vendor.json file that might look like this:
Govendor Dependencies for Heroku or Dokku
If you’re using Docker, Dokku or Heroku you’ll probably want to run
govendor sync at some point before compiling your binary inside your container or use a buildpack that supports it. Also Heroku has a nice help page about govendor.
Note that using
godep you'll have to check in your dependencies directory at the moment, but with
govendor you can just keep the file around and your container will do the installation for you.
To ignore the dependencies in your local project, you can add
vendor/*/ to your
I struggled with missing go dependencies a bit when I was trying out Dokku the first time.
That’s as easy as it gets and kind of an NPM style dependency management option for Go. How do you manage your deps in Golang? Any comments or anything I could do much better? Let me know in the comments or on twitter. :)