Specifying Dependencies

You can use any linux/amd64-compatible package in the App Engine standard environment. These instructions assume you are using the go get command to get the packages directly from supported repositories, such as GitHub, Bitbucket, and LaunchPad.

Declaring and managing dependencies

When deploying your app to App Engine, the Go 1.11 runtime automatically installs all dependencies by taking one of the following approaches:

  • If your app is in a directory on your GOPATH environment variable, App Engine analyzes, copies, and uploads your imports from GOPATH. This approach supports vendor directories.
  • If you use Go Modules through a go.mod file, App Engine uploads only your application files and automatically fetches those dependencies. For more information on declaring private dependencies, see Using private dependencies.

All imports must be absolute imports. For example, use:

import "github.com/example/mypackage"

Using private dependencies

App Engine cannot download your private dependencies during the build process, so you must include them with your application code upon deployment.

You will need to use the replace directive in your go.mod file to declare private dependencies. The following example assumes your app is in the /myapp/ directory:

  1. Change to your app directory:

    cd /myapp
    
  2. Create a directory containing your private dependencies:

    mkdir private
    

    Make sure your private dependency is in the private directory. One approach is by creating a symlink:

    mkdir private/private.example.com
    ln -s /path/to/private.example.com/foo private/private.example.com/foo
    
  3. Update your go.mod file to use the replace directive to use the private directory for your dependency:

    go mod edit -replace=private.example.com/foo=./private/private.example.com/foo
    

    Your go.mod file should now look like:

    Final go.mod file

    module private.example.com/myapp
    
    require private.example.com/foo v1.2.3
    
    replace private.example.com/foo => ./private/private.example.com/foo
    

    Original go.mod file

    module private.example.com/myapp
    
    require private.example.com/foo v1.2.3
    
  4. Do not modify how you import and use your private package. Your import statement should look like:

    import "private.example.com/foo"
    
  5. Include your private dependency in your deployment by deploying your app:

    gcloud app deploy
    

Downloading required packages

Use the go get command to download and manage dependencies.

For example, to depend on the https://github.com/gorilla/mux URL router:

  1. Download the package to your development environment using the following command:

    go get github.com/gorilla/mux
    
  2. Add the package to your list of imports:

    import "github.com/gorilla/mux"
    

Was this page helpful? Let us know how we did:

Send feedback about...

App Engine standard environment for Go 1.11 docs