Specify dependencies in Go Stay organized with collections Save and categorize content based on your preferences.
You can specify your Cloud Run function dependencies witheither aGo Module or avendordirectory.
Specify dependencies with Go modules
To specify Cloud Run functions dependencies with a Go Module,you list them in ago.mod file.When you deploy your function, Go automatically incorporates the dependencies inyourgo.mod file.
To create ago.mod file, seeManaging dependencies in Go.
TheFunctions Frameworkis a required dependency for all functions. AlthoughCloud Run functions installs it on your behalf when the functionis created, we recommend that you include it as an explicit dependency forclarity.
If yourfunction relies on private dependencies, we recommend that youmirrorfunctions-framework to your private registry. Include the mirroredfunctions-framework as a dependency to your function to avoid installing thepackage from the public internet.
Specify dependencies with avendor directory
Cloud Run functions also lets you include your dependencies with avendor directory.Using a vendor directory is helpful if your dependency is not available through adependency manager or if your Cloud Run functions environment's internetaccess is restricted.
Most of the time,vendor directories are maintained with a dependency manager.You can use any dependency manager you like. For example, you can use Go'sModules functionality to create avendor directory from yourgo.mod file.
You must include theFunctions Framework for Go in your vendordirectory. To use the Go toolchain to do this:
Add the following directive to the import block of your Go code:
_"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"Update your
go.modfile to include the new imported package:gomodtidyCreate a
vendordirectory using the contents of yourgo.modfile:gomodvendor
Go versions earlier than 1.16
For versions of Go earlier than 1.16, if you have ago.mod file and avendordirectory, thevendor directory will be ignored when you deploy your function.To ensure that your vendor directory is respected, use a.gcloudignore fileto avoid uploading yourgo.mod andgo.sum files:
Create a
.gcloudignorefile at the root of your project directory with thefollowing contents:go.modgo.sum# Also ignore Git directories. Delete the following two lines if you want to# upload them..git.gitignore
Use private dependencies
If your function's dependencies are hosted in a repository that is notpublicly accessible, you must use avendor directory to fetch yourdependencies before deploying your function. If you plan to use ago.modfile, see the preceding instructions to avoid potential conflicts between thego.mod file and thevendor directory.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.