googleapis/google-cloud-go

GitHub: googleapis/google-cloud-go

Google Cloud 官方 Go 语言客户端库,提供对 GCP 全系服务的类型安全访问和统一身份认证支持。

Stars: 4426 | Forks: 1525

# Google Cloud Client Libraries for Go [![Go 参考](https://pkg.go.dev/badge/cloud.google.com/go.svg)](https://pkg.go.dev/cloud.google.com/go) 用于 [Google Cloud Platform](https://cloud.google.com) 服务的 Go 包。 ## 安装 ``` go get cloud.google.com/go/firestore@latest # Replace firestore with the package you want to use. ``` **注意:** 其中一些包正在开发中,可能会偶尔进行不兼容旧版本的更改。 ## 支持的 API 有关我们已发布 API 的更新列表,请参阅我们的[参考文档](https://cloud.google.com/go/docs/reference)。 ## [支持的 Go 版本](#supported-versions) 我们的库与最近的两个主要 Go 版本兼容,这与 Go 编程语言遵循的[策略](https://go.dev/doc/devel/release#policy)相同。这意味着当前支持的版本是: - Go 1.25 - Go 1.26 ## 身份验证 默认情况下,每个客户端库将使用 [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials) (ADC) 自动配置调用 API 端点时使用的凭据。 在 Google Cloud Platform 环境(如 Compute Engine、Kubernetes Engine 或 App Engine)中使用库时,无需额外的身份验证步骤。有关更多信息,请参阅 [Google 的身份验证方法](https://cloud.google.com/docs/authentication) 和[使用客户端库进行身份验证](https://cloud.google.com/docs/authentication/client-libraries)。 ``` client, err := storage.NewClient(ctx) ``` 对于在其他地方运行的应用程序,例如您的本地开发环境,您可以使用 [Google Cloud CLI](https://cloud.google.com/cli) 中的 `gcloud auth application-default login` 命令在本地文件系统中设置用户凭据。Application Default Credentials 将自动检测这些凭据。有关更多信息,请参阅[为本地开发环境设置 ADC](https://cloud.google.com/docs/authentication/set-up-adc-local-dev-environment)。 或者,您可能需要提供凭据的显式路径。若要使用[服务账号](https://cloud.google.com/docs/authentication#service-accounts) 密钥文件进行身份验证,请将 `GOOGLE_APPLICATION_CREDENTIALS` 环境变量设置为密钥文件的路径,或者以编程方式将 [`option.WithCredentialsFile`](https://pkg.go.dev/google.golang.org/api/option#WithCredentialsFile) 传递给所需包的 `NewClient` 函数。例如: ``` client, err := storage.NewClient(ctx, option.WithCredentialsFile("path/to/keyfile.json")) ``` 您可以使用 [credentials](https://pkg.go.dev/cloud.google.com/go/auth/credentials) 包创建 [auth.Credentials](https://pkg.go.dev/cloud.google.com/go/auth#Credentials),从而对身份验证进行更多控制。 然后将 [`option.WithAuthCredentials`](https://pkg.go.dev/google.golang.org/api/option#WithAuthCredentials) 传递给 `NewClient` 函数: ``` creds, err := credentials.DetectDefault(&credentials.DetectOptions{...}) ... client, err := storage.NewClient(ctx, option.WithAuthCredentials(creds)) ``` ## 贡献 欢迎贡献。请参阅 [CONTRIBUTING](https://github.com/GoogleCloudPlatform/google-cloud-go/blob/main/CONTRIBUTING.md) 文档了解详情。 请注意,本项目发布时附带贡献者行为准则。参与本项目即表示您同意遵守其条款。有关更多信息,请参阅 [Contributor Code of Conduct](https://github.com/GoogleCloudPlatform/google-cloud-go/blob/main/CONTRIBUTING.md#contributor-code-of-conduct)。 ## 链接 - [Google Cloud 上的 Go](https://cloud.google.com/go/home) - [Google Cloud 上的 Go 入门](https://cloud.google.com/go/getting-started) - [App Engine 快速入门](https://cloud.google.com/appengine/docs/standard/go/quickstart) - [Cloud Functions 快速入门](https://cloud.google.com/functions/docs/quickstart-go) - [Cloud Run 快速入门](https://cloud.google.com/run/docs/quickstarts/build-and-deploy#go)
标签:API, App Engine, Application Default Credentials, BigQuery, EVTX分析, Firestore, GCP, Go, Google Cloud, Pub/Sub, Python工具, Ruby工具, 云存储, 云服务, 基础设施, 威胁情报, 客户端库, 容器, 开发者工具, 日志审计, 计算引擎