Apps that run in the Go 1.12+ standard runtime can use any linux/amd64-compatible package.
App Engine requires all import statements in your Go code to specify absolute paths. For example, use:
import "github.com/example/mypackage"
Use Go modules
We recommend that you use Go modules
to manage dependencies in your Go app. You can continue to use the older GOPATH mode
if you aren't ready to migrate
to Go modules.
Starting in Go version 1.22 and later:
You can't use
go getoutside of a module in the legacyGOPATHmode (GO111MODULE=off). For more information, see Tools.Go recommends that you use a
go.modfile for managing dependencies. To install dependencies during deployment, include ago.modfile in the same folder as theapp.yamlfile. For more information about Go versions, and managing dependencies for vendor directories, seeGOPATHand Modules.
When you deploy your app, App Engine uses the go build command to
build your app and matches the behavior of Go itself. To ensure that
your app uses module-aware mode, do the following in your development
environment:
Create your module's
go.modfile in the same directory as yourapp.yamlfile. App Engine searches the current directory and the successive parent directories until it finds ago.modfile.If App Engine doesn't find a
go.modfile, it followsGOPATHmode.If you set the
GO111MODULEenvironment variable, make sure that the variable's value enablesmodule-awaremode. When you deploy your app, App Engine checks your environment forGO111MODULEand matches the behavior of Go itself. App Engine only applies theGO111MODULEvariable setting if you have included ago.modfile for your app.For Go 1.12, don't locate your app directory within the
$GOPATH/srcfolder. If your Go 1.12 app is anywhere in the$GOPATH/srcdirectory tree, App Engine followsGOPATHmode even if you've defined ago.modfile for your app.For Go 1.13 and later, App Engine uses
module-awaremode by default, unlessGO111MODULEoverrides the default or ago.modfile doesn't exist in the app's directory.
Vendoring dependencies
Vendoring copies the packages your app uses into the application directory
instead of downloading modules from their sources during the build process. Go
provides the go build command to
vendor the packages your app needs
into a directory named vendor in your app's root directory.
In Go 1.14 and later, if your app's root directory contains a directory named
vendor, the go build command and the App Engine
deployment process use the packages in the vendor directory instead of
downloading modules.
In Go 1.13 and earlier, vendoring is only available if you set up your
environment to use GOPATH mode.
Use private dependencies
App Engine can't download your private dependencies during the build process, so you must include the dependencies with your application code upon deployment.
Use the replace directive in your go.mod file to declare
private dependencies. The following example assumes your app is in the /myapp/
directory:
Change to your app directory:
cd /myappCreate a directory containing your private dependencies:
mkdir privateMake sure your private dependency is in the
privatedirectory. One approach is by creating a symlink:mkdir private/private.example.com ln -s /path/to/private.example.com/foo private/private.example.com/fooUpdate your
go.modfile to use thereplacedirective to use theprivatedirectory for your dependency:go mod edit -replace=private.example.com/foo=./private/private.example.com/fooYour
go.modfile should now look like:Final
go.modfilemodule private.example.com/myapp require private.example.com/foo v1.2.3 replace private.example.com/foo => ./private/private.example.com/fooOriginal
go.modfilemodule private.example.com/myapp require private.example.com/foo v1.2.3Don't modify how you import and use your private package. Your
importstatement should look like this:import "private.example.com/foo"Include your private dependency in your deployment by deploying your app:
gcloud app deploy