go – cloud.google.com/go Index | Examples | Files | Directories

package cloud

import "cloud.google.com/go"

Package cloud is the root of the packages used to access Google Cloud Services. See https://godoc.org/cloud.google.com/go for a full list of sub-packages.

Client Options

All clients in sub-packages are configurable via client options. These options are described here: https://godoc.org/google.golang.org/api/option.

Authentication and Authorization

All the clients in sub-packages support authentication via Google Application Default Credentials (see https://cloud.google.com/docs/authentication/production), or by providing a JSON key file for a Service Account. See the authentication examples in this package for details.

Timeouts and Cancellation

By default, non-streaming methods, like Create or Get, will have a default deadline applied to the context provided at call time, unless a context deadline is already set. Streaming methods have no default deadline and will run indefinitely. To set timeouts or arrange for cancellation, use contexts. See the examples for details. Transient errors will be retried when correctness allows.

To opt out of default deadlines, set the temporary environment variable GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE to "true" prior to client creation. This affects all Google Cloud Go client libraries. This opt-out mechanism will be removed in a future release. File an issue at https://github.com/googleapis/google-cloud-go if the default deadlines cannot work for you.

Do not attempt to control the initial connection (dialing) of a service by setting a timeout on the context passed to NewClient. Dialing is non-blocking, so timeouts would be ineffective and would only interfere with credential refreshing, which uses the same context.

Connection Pooling

Connection pooling differs in clients based on their transport. Cloud clients either rely on HTTP or gRPC transports to communicate with Google Cloud.

Cloud clients that use HTTP (bigquery, compute, storage, and translate) rely on the underlying HTTP transport to cache connections for later re-use. These are cached to the default http.MaxIdleConns and http.MaxIdleConnsPerHost settings in http.DefaultTransport.

For gRPC clients (all others in this repo), connection pooling is configurable. Users of cloud client libraries may specify option.WithGRPCConnectionPool(n) as a client option to NewClient calls. This configures the underlying gRPC connections to be pooled and addressed in a round robin fashion.

Using the Libraries with Docker

Minimal docker images like Alpine lack CA certificates. This causes RPCs to appear to hang, because gRPC retries indefinitely. See https://github.com/googleapis/google-cloud-go/issues/928 for more information.

Debugging

To see gRPC logs, set the environment variable GRPC_GO_LOG_SEVERITY_LEVEL. See https://godoc.org/google.golang.org/grpc/grpclog for more information.

For HTTP logging, set the GODEBUG environment variable to "http2debug=1" or "http2debug=2".

Inspecting errors

Most of the errors returned by the generated clients can be converted into a `grpc.Status`. Converting your errors to this type can be a useful to get more information about what went wrong while debugging.

 if err != {
    if s, ok := status.FromError(err); ok {
	   log.Println(s.Message())
	   for _, d := range s.Proto().Details {
	      log.Println(d)
	   }
	}
 }

Client Stability

Clients in this repository are considered alpha or beta unless otherwise marked as stable in the README.md. Semver is not used to communicate stability of clients.

Alpha and beta clients may change or go away without notice.

Clients marked stable will maintain compatibility with future versions for as long as we can reasonably sustain. Incompatible changes might be made in some situations, including:

- Security bugs may prompt backwards-incompatible changes.

- Situations in which components are no longer feasible to maintain without making breaking changes, including removal.

- Parts of the client surface may be outright unstable and subject to change. These parts of the surface will be labeled with the note, "It is EXPERIMENTAL and subject to change or removal without notice."

Example (ApplicationDefaultCredentials)

Google Application Default Credentials is the recommended way to authorize and authenticate clients.

For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.

Code:play 

package main

import (
	"context"

	secretmanager "cloud.google.com/go/secretmanager/apiv1"
)

func main() {
	client, err := secretmanager.NewClient(context.Background())
	if err != nil {
		// TODO: handle error.
	}
	_ = client // Use the client.
}
Example (Cancellation)

To arrange for an RPC to be canceled, use context.WithCancel.

Code:play 

package main

import (
	"context"

	secretmanager "cloud.google.com/go/secretmanager/apiv1"

	secretmanagerpb "google.golang.org/genproto/googleapis/cloud/secretmanager/v1"
)

func main() {
	ctx := context.Background()
	// Do not cancel the context passed to NewClient: dialing happens asynchronously,
	// and the context is used to refresh credentials in the background.
	client, err := secretmanager.NewClient(ctx)
	if err != nil {
		// TODO: handle error.
	}
	cctx, cancel := context.WithCancel(ctx)
	defer cancel() // Always call cancel.

	// TODO: Make the cancel function available to whatever might want to cancel the
	// call--perhaps a GUI button.
	req := &secretmanagerpb.DeleteSecretRequest{Name: "projects/proj/secrets/name"}
	if err := client.DeleteSecret(cctx, req); err != nil {
		// TODO: handle error.
	}
}
Example (CredentialsFile)

You can use a file with credentials to authenticate and authorize, such as a JSON key file associated with a Google service account. Service Account keys can be created and downloaded from https://console.developers.google.com/permissions/serviceaccounts.

This example uses the Datastore client, but the same steps apply to the other client libraries underneath this package.

Code:play 

package main

import (
	"context"

	secretmanager "cloud.google.com/go/secretmanager/apiv1"
	"google.golang.org/api/option"
)

func main() {
	client, err := secretmanager.NewClient(context.Background(),
		option.WithCredentialsFile("/path/to/service-account-key.json"))
	if err != nil {
		// TODO: handle error.
	}
	_ = client // Use the client.
}
Example (CredentialsFromJSON)

In some cases (for instance, you don't want to store secrets on disk), you can create credentials from in-memory JSON and use the WithCredentials option.

The google package in this example is at golang.org/x/oauth2/google.

This example uses the Secret Manager client, but the same steps apply to the other client libraries underneath this package. Note that scopes can be found at https://developers.google.com/identity/protocols/googlescopes, and are also provided in all auto-generated libraries: for example, cloud.google.com/go/secretmanager/apiv1 provides DefaultAuthScopes.

Code:play 

package main

import (
	"context"

	secretmanager "cloud.google.com/go/secretmanager/apiv1"
	"golang.org/x/oauth2/google"
	"google.golang.org/api/option"
)

func main() {
	ctx := context.Background()
	creds, err := google.CredentialsFromJSON(ctx, []byte("JSON creds"), secretmanager.DefaultAuthScopes()...)
	if err != nil {
		// TODO: handle error.
	}
	client, err := secretmanager.NewClient(ctx, option.WithCredentials(creds))
	if err != nil {
		// TODO: handle error.
	}
	_ = client // Use the client.
}
Example (Timeout)

To set a timeout for an RPC, use context.WithTimeout.

Code:play 

package main

import (
	"context"
	"time"

	secretmanager "cloud.google.com/go/secretmanager/apiv1"

	secretmanagerpb "google.golang.org/genproto/googleapis/cloud/secretmanager/v1"
)

func main() {
	ctx := context.Background()
	// Do not set a timeout on the context passed to NewClient: dialing happens
	// asynchronously, and the context is used to refresh credentials in the
	// background.
	client, err := secretmanager.NewClient(ctx)
	if err != nil {
		// TODO: handle error.
	}
	// Time out if it takes more than 10 seconds to create a dataset.
	tctx, cancel := context.WithTimeout(ctx, 10*time.Second)
	defer cancel() // Always call cancel.

	req := &secretmanagerpb.DeleteSecretRequest{Name: "projects/project-id/secrets/name"}
	if err := client.DeleteSecret(tctx, req); err != nil {
		// TODO: handle error.
	}
}

Index

Examples

Source Files

doc.go

Directories

PathSynopsis
accessapproval
accessapproval/apiv1Use of Context
analytics
analytics/admin
analytics/admin/apiv1alphaUse of Context
analytics/data
analytics/data/apiv1alphaUse of Context
apigateway
apigateway/apiv1Package apigateway is an auto-generated package for the API Gateway API.
appengine
appengine/apiv1Package appengine is an auto-generated package for the App Engine Admin API.
area120
area120/tables
area120/tables/apiv1alpha1Package tables is an auto-generated package for the Area120 Tables API.
artifactregistry
artifactregistry/apiv1beta2Package artifactregistry is an auto-generated package for the Artifact Registry API.
asset
asset/apiv1Package asset is an auto-generated package for the Cloud Asset API.
asset/apiv1p2beta1Package asset is an auto-generated package for the Cloud Asset API.
asset/apiv1p5beta1Package asset is an auto-generated package for the Cloud Asset API.
assuredworkloads
assuredworkloads/apiv1beta1Use of Context
automl
automl/apiv1Package automl is an auto-generated package for the Cloud AutoML API.
automl/apiv1beta1Package automl is an auto-generated package for the Cloud AutoML API.
billing
billing/apiv1Package billing is an auto-generated package for the Cloud Billing API.
billing/budgets
billing/budgets/apiv1Package budgets is an auto-generated package for the Cloud Billing Budget API.
billing/budgets/apiv1beta1Use of Context
binaryauthorization
binaryauthorization/apiv1beta1Package binaryauthorization is an auto-generated package for the Binary Authorization API.
channel
channel/apiv1Package channel is an auto-generated package for the Cloud Channel API.
civilPackage civil implements types for civil time, a time-zone-independent representation of time that follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second minutes.
cloudbuild
cloudbuild/apiv1Creates and manages builds on Google Cloud Platform.
cloudbuild/apiv1/v2Package cloudbuild is an auto-generated package for the Cloud Build API.
cloudtasks
cloudtasks/apiv2Package cloudtasks is an auto-generated package for the Cloud Tasks API.
cloudtasks/apiv2beta2Package cloudtasks is an auto-generated package for the Cloud Tasks API.
cloudtasks/apiv2beta3Package cloudtasks is an auto-generated package for the Cloud Tasks API.
cmd
cmd/go-cloud-debug-agent
cmd/go-cloud-debug-agent/internal
compute
compute/metadataPackage metadata provides access to Google Compute Engine (GCE) metadata and API service accounts.
containerPackage container contains a deprecated Google Container Engine client.
containeranalysis
containeranalysis/apiv1Package containeranalysis is an auto-generated package for the Container Analysis API.
containeranalysis/apiv1beta1Package containeranalysis is an auto-generated package for the Container Analysis API.
container/apiv1Package container is an auto-generated package for the Kubernetes Engine API.
datacatalog
datacatalog/apiv1Package datacatalog is an auto-generated package for the Google Cloud Data Catalog API.
datacatalog/apiv1beta1Package datacatalog is an auto-generated package for the Google Cloud Data Catalog API.
datalabeling
datalabeling/apiv1beta1Package datalabeling is an auto-generated package for the Data Labeling API.
dataproc
dataproc/apiv1Package dataproc is an auto-generated package for the Cloud Dataproc API.
dataproc/apiv1beta2Package dataproc is an auto-generated package for the Cloud Dataproc API.
dataqna
dataqna/apiv1alphaPackage dataqna is an auto-generated package for the Data QnA API.
debugger
debugger/apiv2Package debugger is an auto-generated package for the Stackdriver Debugger API.
dialogflow
dialogflow/apiv2Package dialogflow is an auto-generated package for the Dialogflow API.
dialogflow/cx
dialogflow/cx/apiv3Package cx is an auto-generated package for the Dialogflow API.
dialogflow/cx/apiv3beta1Package cx is an auto-generated package for the Dialogflow API.
dlp
dlp/apiv2Package dlp is an auto-generated package for the Cloud Data Loss Prevention (DLP) API.
documentai
documentai/apiv1Package documentai is an auto-generated package for the Cloud Document AI API.
documentai/apiv1beta3Package documentai is an auto-generated package for the Cloud Document AI API.
domains
domains/apiv1beta1Package domains is an auto-generated package for the Cloud Domains API.
errorreportingPackage errorreporting is a Google Cloud Error Reporting library.
errorreporting/apiv1beta1Package errorreporting is an auto-generated package for the Error Reporting API.
functions
functions/apiv1Use of Context
functions/metadataPackage metadata provides methods for creating and accessing context.Context objects with Google Cloud Functions metadata.
gaming
gaming/apiv1Use of Context
gaming/apiv1betaUse of Context
gkehub
gkehub/apiv1beta1Package gkehub is an auto-generated package for the GKE Hub.
grafeas
grafeas/apiv1Package grafeas is an auto-generated package for the Container Analysis API.
httpreplayPackage httpreplay provides an API for recording and replaying traffic from HTTP-based Google API clients.
httpreplay/cmd
httpreplay/cmd/httpr
httpreplay/internal
iamPackage iam supports the resource-specific operations of Google Cloud IAM (Identity and Access Management) for the Google Cloud Libraries.
iam/admin
iam/admin/apiv1Package admin is an auto-generated package for the Google Identity and Access Management (IAM) API.
iam/credentials
iam/credentials/apiv1Package credentials is an auto-generated package for the IAM Service Account Credentials API.
internal
iot
iot/apiv1Package iot is an auto-generated package for the Cloud IoT API.
kms
kms/apiv1Package kms is an auto-generated package for the Cloud Key Management Service (KMS) API.
language
language/apiv1Package language is an auto-generated package for the Cloud Natural Language API.
language/apiv1beta2Package language is an auto-generated package for the Cloud Natural Language API.
longrunningPackage longrunning supports Long Running Operations for the Google Cloud Libraries.
longrunning/autogenPackage longrunning is an auto-generated package for the Long Running Operations API.
managedidentities
managedidentities/apiv1Package managedidentities is an auto-generated package for the Managed Service for Microsoft Active Directory API.
mediatranslation
mediatranslation/apiv1beta1Package mediatranslation is an auto-generated package for the Media Translation API.
memcache
memcache/apiv1Package memcache is an auto-generated package for the Cloud Memorystore for Memcached API.
memcache/apiv1beta2Package memcache is an auto-generated package for the Cloud Memorystore for Memcached API.
metastore
metastore/apiv1alphaPackage metastore is an auto-generated package for the Dataproc Metastore API.
metastore/apiv1betaPackage metastore is an auto-generated package for the Dataproc Metastore API.
monitoring
monitoring/apiv3Package monitoring is an auto-generated package for the Cloud Monitoring API.
monitoring/apiv3/v2Package monitoring is an auto-generated package for the Cloud Monitoring API.
monitoring/dashboard
monitoring/dashboard/apiv1Use of Context
networkconnectivity
networkconnectivity/apiv1alpha1Package networkconnectivity is an auto-generated package for the Network Connectivity API.
notebooks
notebooks/apiv1beta1Package notebooks is an auto-generated package for the Notebooks API.
orgpolicy
orgpolicy/apiv2Package orgpolicy is an auto-generated package for the Organization Policy API.
osconfig
osconfig/agentendpoint
osconfig/agentendpoint/apiv1Package agentendpoint is an auto-generated package for the OS Config API.
osconfig/agentendpoint/apiv1betaPackage agentendpoint is an auto-generated package for the Cloud OS Config API.
osconfig/apiv1Package osconfig is an auto-generated package for the OS Config API.
osconfig/apiv1betaPackage osconfig is an auto-generated package for the Cloud OS Config API.
oslogin
oslogin/apiv1Package oslogin is an auto-generated package for the Cloud OS Login API.
oslogin/apiv1betaPackage oslogin is an auto-generated package for the Cloud OS Login API.
phishingprotection
phishingprotection/apiv1beta1Package phishingprotection is an auto-generated package for the Phishing Protection API.
policytroubleshooter
policytroubleshooter/apiv1Package policytroubleshooter is an auto-generated package for the Policy Troubleshooter API.
profilerPackage profiler is a client for the Cloud Profiler service.
profiler/busybenchBusybench is a tool that runs a benchmark with the profiler enabled.
profiler/mocksPackage mocks is a generated GoMock package.
profiler/proftest
recaptchaenterprise
recaptchaenterprise/apiv1Package recaptchaenterprise is an auto-generated package for the reCAPTCHA Enterprise API.
recaptchaenterprise/apiv1beta1Package recaptchaenterprise is an auto-generated package for the reCAPTCHA Enterprise API.
recommendationengine
recommendationengine/apiv1beta1Package recommendationengine is an auto-generated package for the Recommendations AI.
recommender
recommender/apiv1Package recommender is an auto-generated package for the Recommender API.
recommender/apiv1beta1Package recommender is an auto-generated package for the Recommender API.
redis
redis/apiv1Package redis is an auto-generated package for the Google Cloud Memorystore for Redis API.
redis/apiv1beta1Package redis is an auto-generated package for the Google Cloud Memorystore for Redis API.
resourcemanager
resourcemanager/apiv2Package resourcemanager is an auto-generated package for the Cloud Resource Manager API.
resourcesettings
resourcesettings/apiv1Package resourcesettings is an auto-generated package for the Resource Settings API.
retail
retail/apiv2Package retail is an auto-generated package for the Retail API.
rpcreplayPackage rpcreplay supports the capture and replay of gRPC calls.
rpcreplay/proto
rpcreplay/proto/intstore
rpcreplay/proto/rpcreplay
scheduler
scheduler/apiv1Package scheduler is an auto-generated package for the Cloud Scheduler API.
scheduler/apiv1beta1Package scheduler is an auto-generated package for the Cloud Scheduler API.
secretmanager
secretmanager/apiv1Package secretmanager is an auto-generated package for the Secret Manager API.
secretmanager/apiv1beta1Package secretmanager is an auto-generated package for the Secret Manager API.
security
securitycenter
securitycenter/apiv1Package securitycenter is an auto-generated package for the Security Command Center API.
securitycenter/apiv1beta1Package securitycenter is an auto-generated package for the Security Command Center API.
securitycenter/apiv1p1beta1Package securitycenter is an auto-generated package for the Security Command Center API.
securitycenter/settings
securitycenter/settings/apiv1beta1Package settings is an auto-generated package for the Cloud Security Command Center API.
security/privateca
security/privateca/apiv1beta1Use of Context
servicecontrol
servicecontrol/apiv1Use of Context
servicedirectory
servicedirectory/apiv1Package servicedirectory is an auto-generated package for the Service Directory API.
servicedirectory/apiv1beta1Package servicedirectory is an auto-generated package for the Service Directory API.
servicemanagement
servicemanagement/apiv1Use of Context
speech
speech/apiv1Package speech is an auto-generated package for the Cloud Speech-to-Text API.
speech/apiv1p1beta1Package speech is an auto-generated package for the Cloud Speech-to-Text API.
talent
talent/apiv4Use of Context
talent/apiv4beta1Package talent is an auto-generated package for the Cloud Talent Solution API.
texttospeech
texttospeech/apiv1Package texttospeech is an auto-generated package for the Cloud Text-to-Speech API.
third_party
third_party/go
third_party/go/docPackage doc extracts source code documentation from a Go AST.
third_party/pkgsitePackage pkgsite is not for external use.
trace
trace/apiv1Package trace is an auto-generated package for the Stackdriver Trace API.
trace/apiv2Package trace is an auto-generated package for the Stackdriver Trace API.
translatePackage translate is the v2 client for the Google Translation API.
translate/apiv3Package translate is an auto-generated package for the Cloud Translation API.
video
videointelligence
videointelligence/apiv1Package videointelligence is an auto-generated package for the Cloud Video Intelligence API.
videointelligence/apiv1beta2Package videointelligence is an auto-generated package for the Google Cloud Video Intelligence API.
video/transcoder
video/transcoder/apiv1beta1Use of Context
vision
vision/apiv1Package vision is an auto-generated package for the Cloud Vision API.
vision/apiv1p1beta1Package vision is an auto-generated package for the Cloud Vision API.
webrisk
webrisk/apiv1Package webrisk is an auto-generated package for the Web Risk API.
webrisk/apiv1beta1Package webrisk is an auto-generated package for the Web Risk API.
websecurityscanner
websecurityscanner/apiv1Package websecurityscanner is an auto-generated package for the Web Security Scanner API.
workflows
workflows/apiv1betaUse of Context
workflows/executions
workflows/executions/apiv1betaUse of Context
Version
v0.80.0
Published
Mar 23, 2021
Platform
darwin/amd64
Last checked
2 minutes ago

Tools for package owners.