Dependency management planning

  1. Home
  2. Dependency management planning

Go back to GCP Tutorials

In this tutorial we will learn and understand about Dependency management planning.

However, it is recommended that you use Go modules to manage dependencies in your Go app, but you can continue to use the older GOPATH mode if you aren’t ready to migrate to Go modules. Further, when you deploy your app, App Engine uses the go build command to build your app and therefore matches the behavior of Go itself. To ensure that your app uses module-aware mode, do the following in your development environment:

  • Firstly, create your module’s go.mod file in the same directory as your app.yaml file. App Engine searches the current directory, then successive parent directories until it finds a go.mod file.
    • If App Engine doesn’t find a go.mod file, it follows GOPATH mode.
  • Secondly, if you set the GO111MODULE environment variable, make sure the variable’s value enables module-aware mode. When you deploy your app, App Engine checks your environment for GO111MODULE and matches the behavior of Go itself.

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. Further, 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:

  • Firstly, change to your app directory:

cd /myapp

  • Secondly, create a directory containing your private dependencies:

mkdir private

gcp cloud architect practice tests

However, 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

  • Thirdly, 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

Here, your go.mod file should now look like:

module private.example.com/myapp

require private.example.com/foo v1.2.3

replace private.example.com/foo => ./private/private.example.com/foo

  • Next, do not modify how you import and use your private package. Your import statement should look like:

import “private.example.com/foo”

  • Lastly, include your private dependency in your deployment by deploying your app:

gcloud app deploy

Dependency management planning GCP cloud architect  online course

Reference: Google Documentation

Go back to GCP Tutorials

Menu