Go 1.11 已达到支持终止期限,将于 2026 年 1 月 31 日
弃用。弃用后,您将无法部署 Go 1.11 应用,即使您的组织之前曾使用组织政策重新启用旧版运行时的部署也是如此。现有的 Go 1.11 应用在
弃用日期之后将继续运行并接收流量。我们建议您
迁移到最新支持的 Go 版本。
使用 Cloud Storage
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如果您的 Go 1.11 应用在运行时需要读取和写入文件,或者传送影片、图片或其他静态内容等文件,我们建议您使用 Cloud Storage 存储桶。
App Engine 会在您创建应用时创建一个默认存储桶。该存储桶可提供 5GB 的免费存储空间以及 Cloud Storage I/O 操作的免费配额。您可以创建其他 Cloud Storage 存储桶,但只有默认存储桶包含 5GB 的免费存储空间。
将 Cloud Storage 与 App Engine 搭配使用
如需在 App Engine 应用中使用 Cloud Storage 存储桶,请执行以下操作:
查看 App Engine 项目中现有存储桶的名称。从 Cloud Storage 上传或下载数据时,您将需要指定这些名称。
我们建议您将 Cloud Storage 存储桶的名称存储在应用的环境变量中,而不要将其硬编码到应用中。
在应用中,使用 go get cloud.google.com/go/storage
命令将 Cloud Storage 声明为依赖项。或者,您也可以在应用的 go.mod
文件中声明依赖项。请详细了解如何指定依赖项。
使用 Google Cloud 客户端库从您的存储桶上传或下载数据。
如需了解如何传送静态内容,请参阅存储和传送静态文件。
使用默认存储分区
当您创建应用时,App Engine 会创建一个默认存储分区,该存储分区可提供 5GB 的免费存储空间。默认存储桶还可提供 Cloud Storage I/O 操作的免费配额。如需了解详情,请参阅价格、配额和限制。您需要为超出 5GB 限制的存储空间付费。
默认存储分区的名称采用以下格式:
project-id.appspot.com
App Engine 还会在部署应用的新版本时创建一个存储桶以用于临时存储。该存储桶的名称为 staging.project-id.appspot.com
,仅可供 App Engine 使用。应用无法与此存储分区交互。
设置存储桶和对象权限
与您的应用关联的服务账号需要对项目中的存储桶执行读写操作的权限。如需了解所需的权限,请参阅适用于 Cloud Storage 的 IAM 角色。
通常,与您的应用关联的服务账号是默认 App Engine 服务账号。
根据您的组织政策配置,默认服务账号可能会自动被授予项目的 Editor 角色。我们强烈建议您通过强制执行 iam.automaticIamGrantsForDefaultServiceAccounts
组织政策限制条件来停用自动角色授予功能。如果您的组织是在 2024 年 5 月 3 日之后创建的,则默认情况下会强制执行此限制条件。
如果您停用自动角色授予功能,则必须决定向默认服务账号授予哪些角色,然后自行授予这些角色。
如果默认服务账号已具有 Editor 角色,我们建议您将 Editor 角色替换为权限较少的角色。如需安全地修改服务账号的角色,请使用 Policy Simulator 查看更改的影响,然后授予和撤消相应的角色。
如需了解如何允许其他用户、应用或项目访问存储桶及其内容,请参阅设置存储桶权限和设置对象权限。
将 Cloud Storage 与本地开发服务器搭配使用
App Engine 本地开发服务器不会模拟 Cloud Storage,因此必须通过互联网将所有 Cloud Storage 请求发送到实际的 Cloud Storage 存储桶。
价格、配额和限制
通过 Cloud Storage 客户端库调用 Cloud Storage 不会产生带宽费用。不过,此操作会产生操作费用。此外,由于该客户端库使用 URL Fetch 服务与 Cloud Storage 进行交互,因此这些调用将计入 URL Fetch 配额。
请注意,Cloud Storage 是付费服务;您需要按照 Cloud Storage 价格表支付费用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-20。
[[["易于理解","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-08-20。"],[[["\u003cp\u003eApp Engine recommends using a Cloud Storage bucket for reading, writing, and serving files during runtime in Go 1.11 apps.\u003c/p\u003e\n"],["\u003cp\u003eWhen you create an app, App Engine provides a default bucket with the first 5GB of storage and a free quota for Cloud Storage I/O operations.\u003c/p\u003e\n"],["\u003cp\u003eTo interact with Cloud Storage from your app, you should specify bucket names using environment variables and declare Cloud Storage as a dependency using the \u003ccode\u003ego get\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine automatically creates a temporary staging bucket for deploying new versions, but it's not accessible to apps.\u003c/p\u003e\n"],["\u003cp\u003eThe service account linked to your app needs the appropriate permissions to interact with buckets, and you should consider replacing the Editor role with more restrictive roles for enhanced security.\u003c/p\u003e\n"]]],[],null,["# Using Cloud Storage\n\nIf your Go 1.11 app needs to read and write files during runtime,\nor serve files such as movies, images or other static content, we recommend you\nuse a [Cloud Storage](/storage/docs) bucket.\n\nApp Engine creates a [default bucket](#default_bucket) when you create\nan app. This bucket provides the first 5GB of storage for free and includes a\nfree quota for Cloud Storage I/O operations. You can\n[create other Cloud Storage buckets](/storage/docs/creating-buckets),\nbut only the default bucket includes the first 5GB of storage for free.\n\nUsing Cloud Storage with App Engine\n-----------------------------------\n\nTo use a Cloud Storage bucket from an App Engine app:\n\n1. [View the names of the existing buckets](/storage/docs/listing-buckets)\n in your App Engine project. You'll specify these names when you\n upload or download data from Cloud Storage.\n\n We recommend that you store the names of your Cloud Storage buckets\n in your app's [environment variables](/appengine/docs/standard/reference/app-yaml#environment_variables)\n instead of hard coding them into your app.\n2. In your app, declare Cloud Storage as a dependency\n\n by using the `go get cloud.google.com/go/storage` command. Alternatively,\n you can declare dependencies in your app's `go.mod` file. Learn more\n [about specifying dependencies](/appengine/docs/legacy/standard/go111/specifying-dependencies).\n\n \u003cbr /\u003e\n\n3.\n Use the Google Cloud Client Library to\n [upload](/storage/docs/uploading-objects)\n or [download](/storage/docs/downloading-objects)\n data from your buckets.\n\n\n For information about serving static content, see [Storing and Serving\n Static Files](/appengine/docs/legacy/standard/go111/serving-static-files).\n\n### Using the default bucket\n\nWhen you create an app, App Engine creates a default bucket that\nprovides the first 5GB of storage for free. The default bucket also includes\na free quota for Cloud Storage I/O operations. See\n[Pricing, quotas, and limits](#pricing_quotas_and_limits) for details. You will\nbe charged for storage over the 5GB limit.\n\nThe name of the default bucket is in the following format: \n\n```\nproject-id.appspot.com\n```\n\n\u003cbr /\u003e\n\nApp Engine also creates a bucket that it uses for temporary\nstorage when it deploys new versions of your app. This bucket, named\n`staging.`\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e`.appspot.com`, is for use by\nApp Engine only. Apps can't interact with this bucket.\n\n### Setting bucket and object permissions\n\nThe service account that's associated with your app needs permissions to read\nand write to buckets in your project. To learn which permissions are required,\nsee [IAM roles for\nCloud Storage](/storage/docs/access-control/iam-roles).\n\nTypically, the\nservice account that's associated with your app is the [default\nApp Engine service\naccount](/appengine/docs/legacy/standard/go111/service-account).\n\n\nDepending on your organization policy configuration, the default service account might\nautomatically be granted the [Editor role](/iam/docs/roles-overview#basic) on your\nproject. We strongly recommend that you disable the automatic role grant by [enforcing the `iam.automaticIamGrantsForDefaultServiceAccounts` organization policy\nconstraint](/resource-manager/docs/organization-policy/restricting-service-accounts#disable_service_account_default_grants). If you created your organization after May 3, 2024, this\nconstraint is enforced by default.\n\n\nIf you disable the automatic role grant, you must decide which roles to grant to the default\nservice accounts, and then [grant these\nroles](/iam/docs/granting-changing-revoking-access) yourself.\n\n\nIf the default service account already has the Editor role, we recommend that you replace the\nEditor role with less permissive roles.To safely modify the service account's roles, use [Policy Simulator](/policy-intelligence/docs/simulate-iam-policies) to see the impact of\nthe change, and then [grant and revoke the\nappropriate roles](/iam/docs/granting-changing-revoking-access).\n\n\u003cbr /\u003e\n\nFor information about allowing other users, apps, or projects to access a bucket\nand its contents, see\n[Setting bucket permissions](/storage/docs/cloud-console#_bucketpermission)\nand\n[Setting object permissions](/storage/docs/cloud-console#_permissions).\n\nUsing Cloud Storage with the local development server\n-----------------------------------------------------\n\nThe App Engine local development server doesn't emulate Cloud Storage,\nso all Cloud Storage requests must be sent over the Internet to an\nactual Cloud Storage bucket.\n\nPricing, quotas, and limits\n---------------------------\n\nThere are no bandwidth charges associated with Cloud Storage client library\ncalls to Cloud Storage. However, there are\n[operations charges](/storage/pricing#operations-pricing).\nIn addition, the calls count against your\n[URL fetch quota](/appengine/docs/quotas#UrlFetch)\nas the library uses the URL Fetch service to interact with Cloud Storage.\n\nNotice that Cloud Storage is a pay-to-use service;\nyou will be charged according to the Cloud Storage\n[price sheet](/storage/pricing)."]]