Go Dependencies via GB
Last updated 04 February 2016
Table of Contents
This guide outlines how to fully utilize Heroku’s support for specifying dependencies for your Go application with gb.
gb is an alternative build tool for Go and operates on the concept of a project. A
gb project is a workspace for all the Go code that is required to build your application.
gb, like many other tools, vendors external project dependencies into a
vendor/ directory. All of the projects source code, including the
vendor/ directory should be checked into your git repository.
When pushing code that uses gb Heroku will use several of your application’s config variables to determine the go version (
heroku config:set GOVERSION=go1.5) and any linker symbols / values.
GOVERSION isn’t set the go version will default to the current, latest released go version supported by heroku.
$ go get -u github.com/constabulary/gb/...
Unlike the normal go tooling, with
gb your project does not, and should not, live in the
gb project is any directory with a
src/ sub directory.
The code for your project is put into packages. These packages reside in sub directories of
src/. These packages follow the same rules as with the standard go tooling.
You can find more information about
gb projects here.
gb vendor fetch <dep>the new dependency.
- Edit your application’s source code to import & use the new dependency.
- Commit the changes with
git add -A .; git commit -m "Using <dependency>".
Listing vendored dependencies
$ gb vendor list github.com/dustin/go-broadcast https://github.com/dustin/go-broadcast master 3bdf6d4a7164a50bc19d5f230e2981d87d2584f1 github.com/gin-gonic/gin https://github.com/gin-gonic/gin master 52fcc5dbf6e94df33ad313858fb94b713e9d1b4a github.com/manucorporat/sse https://github.com/manucorporat/sse master fe6ea2c8e398672518ef204bf0fbd9af858d0e15 github.com/manucorporat/stats https://github.com/manucorporat/stats master 8f2d6ace262eba462e9beb552382c98be51d807b github.com/mattn/go-colorable https://github.com/mattn/go-colorable master 3dac7b4f76f6e17fb39b768b89e3783d16e237fe golang.org/x/net/context https://go.googlesource.com/net/context master 78e1654ef40b8b993e3355307740b1cac8f1db20 gopkg.in/bluesuncorp/validator.v5 https://gopkg.in/bluesuncorp/validator.v5 master d5acf1dac43705f8bfbb71d878e290e2bed3950b
Updating an existing dependency
gb vendor update <dependency>.
- Inspect the changes with
git diff(or similar).
- Commit the changes with
git add -A vendor; git commit -m "Update <dependency>".
Removing unused dependencies
gb vendor purge