Building and managing Go function dependencies
At the build stage, Cloud Functions automatically installs dependencies required for a Go function to run when creating a new function version.
Note
The build gets the ycf build tag.
Cloud Functions supports two automatic dependency management methods for this purpose: modules and the dep utility.
mod
ModulesGo language. They represent the main and recommended dependency management method for 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 state the Go language version, because 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 obsolete and deprecated for version 1.16 of the language.
DepGo.
To deliver dependencies using dep, upload the Gopkg.toml and Gopkg.lock files together with the function source code. In which case the dep ensure command will be invoked just ahead of building the code.
Note
If you have both go.mod and Gopkg.toml among the files, builder performance is not guaranteed. We do not recommend using these two files at the same time.
The process of installing dependencies has resource and execution time limits. For more information, see Quotas and limits in Cloud Functions. You can view the dependency installation log using the link that appears in the list of operations.