Building and managing Go function dependencies
At the build stage, Cloud Functions automatically installs dependencies required for a Go function when creating a new function version.
Note
The build gets the ycf build tag.
For this, Cloud Functions supports two methods of automatic dependency management: modules and the dep utility.
mod
ModulesGo. They are the primary and recommended way to manage dependencies in Cloud Functions.
To deliver dependencies using modules, upload the go.mod file together with the function source code. This will install the latest versions of the packages specified in this file. To specify the versions explicitly, also upload the go.sum file.
Warning
Make sure the module name in the go.mod file is not main.
The go.mod file must not specify the Go version, since the plugin generated by the builder must use exactly the same Go version as the runtime environment.
dep
Warning
This method of managing dependencies is deprecated and no longer supported in language version 1.16.
DepGo.
To deliver dependencies using dep, upload the Gopkg.toml and Gopkg.lock files together with the function source code. In this case, the dep ensure command runs just before building the code.
Note
If you have both go.mod and Gopkg.toml among the files, the build system may not work as expected. We do not recommend using these two files at the same time.
Dependency installation is limited in terms of resources and execution time. For more information, see Quotas and limits in Cloud Functions. You can view the dependency installation log via the link displayed in the list of operations.