Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Go
  • Go Dependency Management
  • Go Dependencies via Godep

Go Dependencies via Godep

English — 日本語に切り替える

Last updated January 26, 2022

Table of Contents

  • Using godep
  • Adding new dependencies
  • Updating an existing dependency
  • Changing the version of Go used to build your application
  • Migrating from Godep workspace to go1.6 with a vendor/ directory

This guide outlines how to fully utilize Heroku’s support for specifying dependencies for your Go application with godep.

Godep is a tool that vendors your application’s dependencies into its source repository thereby enabling repeatable builds and reducing external build dependencies.

Using godep

Install/update godep:

$ go get -u github.com/tools/godep

To have godep determine, save and rewrite your application’s dependencies, navigate to your application’s directory within $GOPATH and run the following command:

$ godep save ./...

This will have the following effects:

  1. A Godeps/Godeps.json file will be created that contains the JSON representation of the application’s dependencies, the packages that we’re working on (the package spec) and the version of Go you are using locally.
  2. Each dependency will be copied into a subdirectory of vendor/.

These changes need to be committed to your application’s git repository like so:

$ git add -A .
$ git commit -m "Vendoring dependencies"

The Godeps/Godeps.json file is used by Heroku’s Go buildpack to determine the version of Go to use when compiling the application. Because of this you should run godep save ./... on your application even if it doesn’t have any external dependencies.

Adding new dependencies

  1. go get the new dependency.
  2. Edit your application’s source code to import the new dependency.
  3. Run godep save ./... to update Godeps/Godeps.json and copy the dependencies source to vendor/.

Updating an existing dependency

  1. go get -u <dependency>.
  2. godep update <dependency>.
  3. Inspect the changes with git diff (or similar).
  4. Commit the changes with git add -A .; git commit -m "Update <dependency>".

Changing the version of Go used to build your application

The major version of the Go toolchain is recorded in the Godeps/Godeps.json file in the GoVersion key and begins with go.

{
  "ImportPath": "github.com/heroku/go-getting-started",
  "GoVersion": "go1.6",
...
}

You can change the version in one of two ways:

  1. Installing and using a new major go version locally and then running godep update -goversion. This adjusts Godeps/Godeps.json files based on the version of go you are using.

  2. Manually changing the value of GoVersion in Godeps/Godeps.json to a valid major Go version (see go version).

Then committing the changes and pushing the app to Heroku will recompile the application with the current version of the newly specified major go version.

Specifying a specific minor version of Go

Godep records only the major version of the go toolchain (eg: go1.6 instead of go1.6.2). One each push Heroku will use the latest supported minor version of the toolchain to compile your application. This is our recommended setup. If however, you require a specific minor revision, this can be accomplished by specifying the full minor version in the GoVersion field of the Godeps/Godeps.json file.

Using a development version of Go

If you require a development version of Go, you can set the GoVersion field of the Godeps/Godeps.json file to devel-<short sha>. The <short-sha> should be replaced with the short git sha of the commit Heroku should use. On the next push, Heroku will retrieve that revision of Go from Github and compile it, using that version to build your application.

Migrating from Godep workspace to go1.6 with a vendor/ directory

  • Make sure you are using go1.6 (go version).
  • Make sure you have the latest godep (go get -u github.com/tools/godep)
  • godep restore, to ensure the project’s dependencies are “restored” to your $GOPATH.
  • If you are using rewrites run godep save -r=false <pkg spec> to remove them.
  • rm -rf Godeps to remove old dependency info.
  • godep save <pkg spec> to re-save the deps to vendor/.
  • git add -A; git commit -am "Upgrade to go1.6" to commit the changes to the repo.
  • git push heroku master to deploy using go1.6 and a vendor/ directory.

If you run into any problems please file a support ticket. Output from the above steps would be most helpful when troubleshooting.

Keep reading

  • Go Dependency Management

Feedback

Log in to submit feedback.

Go Dependencies via govendor Go Dependencies via govendor

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences