安装以下工具,为 Google Cloud 上的 Go 应用开发和部署准备好环境。
安装 Go
要安装 Go,请参阅 Go 使用入门。
确认您安装的是最新版 Go:
go version
安装编辑器
为了最大限度地提高 Go 开发效率,这些常用编辑器插件和 IDE 提供了以下功能:
- 全面集成的调试功能
- 语法突出显示
- 代码补全
安装 Google Cloud CLI
Google Cloud CLI 是一套适用于 Google Cloud的工具。其中包含可用于通过命令行访问 Compute Engine、Cloud Storage、BigQuery 以及其他服务的 gcloud
和 bq
命令行工具。这些工具既能以交互方式使用,也可以在自动化脚本中运行。
例如,如需将采用 main
软件包的 Go Web 应用部署到 App Engine,请运行以下命令:
gcloud app deploy
如需安装 gcloud CLI,请参阅安装 gcloud CLI。
安装 Go 版 Cloud 客户端库
Go 开发者集成Google Cloud 服务(例如 Datastore 和 Cloud Storage)的惯用方式是使用 Go 版 Cloud 客户端库。
例如,如需为单个 API(例如 Cloud Storage API)安装软件包,请执行以下操作:
如果您的项目已有 Go 模块,请切换到该目录。否则,请创建一个模块:
go mod init YOUR_MODULE_NAME
将
YOUR_MODULE_NAME
替换为新模块的名称。在项目中使用 Cloud Storage 软件包:
go get cloud.google.com/go/storage
设置身份验证
如需在本地开发环境中使用 Cloud 客户端库,请设置应用默认凭据。
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
如需了解详情,请参阅使用客户端库时进行身份验证。
安装其他实用工具
如需查看完整的 Go 工具和库,请参阅 GitHub 上的这个 Go 框架、库和软件列表。
后续步骤
- 详细了解 Go on Google Cloud。
- 在 App Engine 上部署 Go 应用。
- 探索 Google 的身份验证方法。
- 浏览 Google Cloud 产品文档。
- 克隆 GitHub 中的 Go 示例代码库。