[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Specify dependencies in Go\n\nYou can specify your Cloud Run function dependencies with\neither a [Go Module](https://golang.org/doc/go1.11#modules) or a `vendor`\ndirectory.\n\nSpecify dependencies with Go modules\n------------------------------------\n\nTo specify Cloud Run functions dependencies with a Go Module,\nyou list them in a `go.mod` file.\nWhen you deploy your function, Go automatically incorporates the dependencies in\nyour `go.mod` file.\n\nTo create a `go.mod` file, see\n[Managing dependencies in Go](https://go.dev/doc/modules/managing-dependencies).\n\nThe [Functions Framework](https://github.com/GoogleCloudPlatform/functions-framework-go)\nis a required dependency for all functions. Although\nCloud Run functions installs it on your behalf when the function\nis created, we recommend that you include it as an explicit dependency for\nclarity.\n\nIf your\nfunction relies on private dependencies, we recommend that you\nmirror `functions-framework` to your private registry. Include the mirrored\n`functions-framework` as a dependency to your function to avoid installing the\npackage from the public internet.\n\nSpecify dependencies with a `vendor` directory\n----------------------------------------------\n\nCloud Run functions also lets you include your dependencies with a\n[`vendor` directory](https://golang.org/cmd/go/#hdr-Vendor_Directories).\nUsing a vendor directory is helpful if your dependency is not available through a\ndependency manager or if your Cloud Run functions environment's internet\naccess is restricted.\n\nMost of the time, `vendor` directories are maintained with a dependency manager.\nYou can use any dependency manager you like. For example, you can use Go's\nModules functionality to create a `vendor` directory from your `go.mod` file.\n\nYou must include the [Functions Framework for Go](https://github.com/GoogleCloudPlatform/functions-framework-go) in your vendor\ndirectory. To use the Go toolchain to do this:\n\n1. Add the following directive to the import block of your Go code:\n\n _ \"github.com/GoogleCloudPlatform/functions-framework-go/funcframework\"\n\n2. Update your `go.mod` file to include the new imported package:\n\n go mod tidy\n\n3. Create a `vendor` directory using the contents of your `go.mod` file:\n\n go mod vendor\n\n### Go versions earlier than 1.16\n\nFor versions of Go earlier than 1.16, if you have a `go.mod` file and a `vendor`\ndirectory, the `vendor` directory will be ignored when you deploy your function.\nTo ensure that your vendor directory is respected, use a\n[`.gcloudignore`](/sdk/gcloud/reference/topic/gcloudignore) file\nto avoid uploading your `go.mod` and `go.sum` files:\n\n1. Create a `.gcloudignore` file at the root of your project directory with the\n following contents:\n\n ```sh\n go.mod\n go.sum\n\n # Also ignore Git directories. Delete the following two lines if you want to\n # upload them.\n .git\n .gitignore\n ```\n\n| **Note:** Learn more about Cloud Run policy for [supporting existing deployments](/functions/docs/concepts/go-runtime#go_116_public_preview) for functions based on a version earlier than 1.16.\n\nUse private dependencies\n------------------------\n\nIf your function's dependencies are hosted in a repository that is not\npublicly accessible, you must use a `vendor` directory to fetch your\ndependencies before deploying your function. If you plan to use a `go.mod`\nfile, see the preceding instructions to avoid potential conflicts between the\n`go.mod` file and the `vendor` directory."]]