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 examples below.
Google Application Default Credentials (ADC) is the recommended way to authorize and authenticate clients. For information on how to create and obtain Application Default Credentials, see https://cloud.google.com/docs/authentication/production. Here is an example of a client using ADC to authenticate:
client, err := secretmanager.NewClient(context.Background()) if err != nil { // TODO: handle error. } _ = client // Use the client.
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.cloud.google.com/iam-admin/serviceaccounts. This example uses the Secret Manger client, but the same steps apply to the other client libraries underneath this package. Example:
client, err := secretmanager.NewClient(context.Background(), option.WithCredentialsFile("/path/to/service-account-key.json")) if err != nil { // TODO: handle error. } _ = client // Use the client.
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/oauth2/scopes, and are also provided in all auto-generated libraries: for example, cloud.google.com/go/secretmanager/apiv1 provides DefaultAuthScopes. Example:
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.
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. Transient errors will be retried when correctness allows.
Here is an example of how to set a timeout for an RPC, use context.WithTimeout:
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. }
Here is an example of how to arrange for an RPC to be canceled, use context.WithCancel:
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. }
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."
Index ¶
Source Files ¶
doc.go
Directories ¶
Path | Synopsis |
---|---|
analytics | |
analytics/admin | |
analytics/admin/apiv1alpha | Package admin is an auto-generated package for the Google Analytics Admin API. |
analytics/data | |
analytics/data/apiv1alpha | Package data is an auto-generated package for the Google Analytics Data API. |
area120 | |
area120/tables | |
area120/tables/apiv1alpha1 | Package tables is an auto-generated package for the Area120 Tables API. |
civil | Package 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/apiv1 | Creates and manages builds on Google Cloud Platform. |
cloudbuild/apiv1/v2 | Package cloudbuild is an auto-generated package for the Cloud Build API. |
cmd | |
cmd/go-cloud-debug-agent | |
cmd/go-cloud-debug-agent/internal | |
compute | |
compute/apiv1 | Package compute is an auto-generated package for the Google Compute Engine API. |
compute/metadata | Package metadata provides access to Google Compute Engine (GCE) metadata and API service accounts. |
datastream | |
datastream/apiv1alpha1 | Package datastream is an auto-generated package for the Datastream API. |
debugger | |
debugger/apiv2 | Package debugger is an auto-generated package for the Stackdriver Debugger API. |
dialogflow | |
dialogflow/apiv2 | Package dialogflow is an auto-generated package for the Dialogflow API. |
dialogflow/cx | |
dialogflow/cx/apiv3 | Package cx is an auto-generated package for the Dialogflow API. |
dialogflow/cx/apiv3beta1 | Package cx is an auto-generated package for the Dialogflow API. |
dlp | |
dlp/apiv2 | Package dlp is an auto-generated package for the Cloud Data Loss Prevention (DLP) API. |
documentai | |
documentai/apiv1 | Package documentai is an auto-generated package for the Cloud Document AI API. |
documentai/apiv1beta3 | Package documentai is an auto-generated package for the Cloud Document AI API. |
domains | |
domains/apiv1beta1 | Package domains is an auto-generated package for the Cloud Domains API. |
errorreporting | Package errorreporting is a Google Cloud Error Reporting library. |
errorreporting/apiv1beta1 | Package errorreporting is an auto-generated package for the Error Reporting API. |
essentialcontacts | |
essentialcontacts/apiv1 | Package essentialcontacts is an auto-generated package for the Essential Contacts API. |
eventarc | |
eventarc/apiv1 | Package eventarc is an auto-generated package for the Eventarc API. |
functions | |
functions/apiv1 | Package functions is an auto-generated package for the Cloud Functions API. |
functions/metadata | Package metadata provides methods for creating and accessing context.Context objects with Google Cloud Functions metadata. |
gaming | |
gaming/apiv1 | Package gaming is an auto-generated package for the Game Services API. |
gaming/apiv1beta | Package gaming is an auto-generated package for the Game Services API. |
gkeconnect | |
gkeconnect/gateway | |
gkeconnect/gateway/apiv1beta1 | Package gateway is an auto-generated package for the Connect Gateway API. |
gkehub | |
gkehub/apiv1beta1 | Package gkehub is an auto-generated package for the GKE Hub. |
grafeas | |
grafeas/apiv1 | Package grafeas is an auto-generated package for the Container Analysis API. |
gsuiteaddons | |
gsuiteaddons/apiv1 | Package gsuiteaddons is an auto-generated package for the Google Workspace Add-ons API. |
httpreplay | Package httpreplay provides an API for recording and replaying traffic from HTTP-based Google API clients. |
httpreplay/cmd | |
httpreplay/cmd/httpr | |
httpreplay/internal | |
iam | Package iam supports the resource-specific operations of Google Cloud IAM (Identity and Access Management) for the Google Cloud Libraries. |
iam/admin | |
iam/admin/apiv1 | Package admin is an auto-generated package for the Google Identity and Access Management (IAM) API. |
iam/credentials | |
iam/credentials/apiv1 | Package credentials is an auto-generated package for the IAM Service Account Credentials API. |
iap | |
iap/apiv1 | Package iap is an auto-generated package for the Cloud Identity-Aware Proxy API. |
internal | |
iot | |
iot/apiv1 | Package iot is an auto-generated package for the Cloud IoT API. |
kms | |
kms/apiv1 | Package kms is an auto-generated package for the Cloud Key Management Service (KMS) API. |
language | |
language/apiv1 | Package language is an auto-generated package for the Cloud Natural Language API. |
language/apiv1beta2 | Package language is an auto-generated package for the Google Cloud Natural Language API. |
lifesciences | |
lifesciences/apiv2beta | Package lifesciences is an auto-generated package for the Cloud Life Sciences API. |
longrunning | Package longrunning supports Long Running Operations for the Google Cloud Libraries. |
longrunning/autogen | Package longrunning is an auto-generated package for the Long Running Operations API. |
managedidentities | |
managedidentities/apiv1 | Package managedidentities is an auto-generated package for the Managed Service for Microsoft Active Directory API. |
mediatranslation | |
mediatranslation/apiv1beta1 | Package mediatranslation is an auto-generated package for the Media Translation API. |
memcache | |
memcache/apiv1 | Package memcache is an auto-generated package for the Cloud Memorystore for Memcached API. |
memcache/apiv1beta2 | Package memcache is an auto-generated package for the Cloud Memorystore for Memcached API. |
metastore | |
metastore/apiv1 | Package metastore is an auto-generated package for the Dataproc Metastore API. |
metastore/apiv1alpha | Package metastore is an auto-generated package for the Dataproc Metastore API. |
metastore/apiv1beta | Package metastore is an auto-generated package for the Dataproc Metastore API. |
monitoring | |
monitoring/apiv3 | Package monitoring is an auto-generated package for the Cloud Monitoring API. |
monitoring/apiv3/v2 | Package monitoring is an auto-generated package for the Cloud Monitoring API. |
monitoring/dashboard | |
monitoring/dashboard/apiv1 | Package dashboard is an auto-generated package for the Cloud Monitoring API. |
networkconnectivity | |
networkconnectivity/apiv1alpha1 | Package networkconnectivity is an auto-generated package for the Network Connectivity API. |
networkmanagement | |
networkmanagement/apiv1 | Package networkmanagement is an auto-generated package for the Network Management API. |
notebooks | |
notebooks/apiv1beta1 | Package notebooks is an auto-generated package for the Notebooks API. |
orgpolicy | |
orgpolicy/apiv2 | Package orgpolicy is an auto-generated package for the Organization Policy API. |
osconfig | |
osconfig/agentendpoint | |
osconfig/agentendpoint/apiv1 | Package agentendpoint is an auto-generated package for the OS Config API. |
osconfig/agentendpoint/apiv1beta | Package agentendpoint is an auto-generated package for the Cloud OS Config API. |
osconfig/apiv1 | Package osconfig is an auto-generated package for the OS Config API. |
osconfig/apiv1alpha | Package osconfig is an auto-generated package for the OS Config API. |
osconfig/apiv1beta | Package osconfig is an auto-generated package for the Cloud OS Config API. |
oslogin | |
oslogin/apiv1 | Package oslogin is an auto-generated package for the Cloud OS Login API. |
oslogin/apiv1beta | Package oslogin is an auto-generated package for the Cloud OS Login API. |
phishingprotection | |
phishingprotection/apiv1beta1 | Package phishingprotection is an auto-generated package for the Phishing Protection API. |
policytroubleshooter | |
policytroubleshooter/apiv1 | Package policytroubleshooter is an auto-generated package for the Policy Troubleshooter API. |
privatecatalog | |
privatecatalog/apiv1beta1 | Package privatecatalog is an auto-generated package for the Cloud Private Catalog API. |
profiler | Package profiler is a client for the Cloud Profiler service. |
profiler/busybench | Busybench is a tool that runs a benchmark with the profiler enabled. |
profiler/mocks | Package mocks is a generated GoMock package. |
profiler/proftest | |
recaptchaenterprise | |
recaptchaenterprise/apiv1 | Package recaptchaenterprise is an auto-generated package for the reCAPTCHA Enterprise API. |
recaptchaenterprise/apiv1beta1 | Package recaptchaenterprise is an auto-generated package for the reCAPTCHA Enterprise API. |
recommendationengine | |
recommendationengine/apiv1beta1 | Package recommendationengine is an auto-generated package for the Recommendations AI. |
recommender | |
recommender/apiv1 | Package recommender is an auto-generated package for the Recommender API. |
recommender/apiv1beta1 | Package recommender is an auto-generated package for the Recommender API. |
redis | |
redis/apiv1 | Package redis is an auto-generated package for the Google Cloud Memorystore for Redis API. |
redis/apiv1beta1 | Package redis is an auto-generated package for the Google Cloud Memorystore for Redis API. |
resourcemanager | |
resourcemanager/apiv2 | Package resourcemanager is an auto-generated package for the Cloud Resource Manager API. |
resourcesettings | |
resourcesettings/apiv1 | Package resourcesettings is an auto-generated package for the Resource Settings API. |
retail | |
retail/apiv2 | Package retail is an auto-generated package for the Retail API. |
rpcreplay | Package rpcreplay supports the capture and replay of gRPC calls. |
rpcreplay/proto | |
rpcreplay/proto/intstore | |
rpcreplay/proto/rpcreplay | |
scheduler | |
scheduler/apiv1 | Package scheduler is an auto-generated package for the Cloud Scheduler API. |
scheduler/apiv1beta1 | Package scheduler is an auto-generated package for the Cloud Scheduler API. |
secretmanager | |
secretmanager/apiv1 | Package secretmanager is an auto-generated package for the Secret Manager API. |
secretmanager/apiv1beta1 | Package secretmanager is an auto-generated package for the Secret Manager API. |
security | |
securitycenter | |
securitycenter/apiv1 | Package securitycenter is an auto-generated package for the Security Command Center API. |
securitycenter/apiv1beta1 | Package securitycenter is an auto-generated package for the Security Command Center API. |
securitycenter/apiv1p1beta1 | Package securitycenter is an auto-generated package for the Security Command Center API. |
securitycenter/settings | |
securitycenter/settings/apiv1beta1 | Package settings is an auto-generated package for the Cloud Security Command Center API. |
security/privateca | |
security/privateca/apiv1 | Package privateca is an auto-generated package for the Certificate Authority API. |
security/privateca/apiv1beta1 | Package privateca is an auto-generated package for the Certificate Authority API. |
servicecontrol | |
servicecontrol/apiv1 | Package servicecontrol is an auto-generated package for the Service Control API. |
servicedirectory | |
servicedirectory/apiv1 | Package servicedirectory is an auto-generated package for the Service Directory API. |
servicedirectory/apiv1beta1 | Package servicedirectory is an auto-generated package for the Service Directory API. |
servicemanagement | |
servicemanagement/apiv1 | Package servicemanagement is an auto-generated package for the Service Management API. |
serviceusage | |
serviceusage/apiv1 | Package serviceusage is an auto-generated package for the Service Usage API. |
shell | |
shell/apiv1 | Package shell is an auto-generated package for the Cloud Shell API. |
speech | |
speech/apiv1 | Package speech is an auto-generated package for the Cloud Speech-to-Text API. |
speech/apiv1p1beta1 | Package speech is an auto-generated package for the Cloud Speech-to-Text API. |
talent | |
talent/apiv4 | Package talent is an auto-generated package for the Cloud Talent Solution API. |
talent/apiv4beta1 | Package talent is an auto-generated package for the Cloud Talent Solution API. |
texttospeech | |
texttospeech/apiv1 | Package texttospeech is an auto-generated package for the Cloud Text-to-Speech API. |
third_party | |
third_party/go | |
third_party/go/doc | Package doc extracts source code documentation from a Go AST. |
third_party/pkgsite | Package pkgsite is not for external use. |
tpu | |
tpu/apiv1 | Package tpu is an auto-generated package for the Cloud TPU API. |
trace | |
trace/apiv1 | Package trace is an auto-generated package for the Stackdriver Trace API. |
trace/apiv2 | Package trace is an auto-generated package for the Stackdriver Trace API. |
translate | Package translate is the v2 client for the Google Translation API. |
translate/apiv3 | Package translate is an auto-generated package for the Cloud Translation API. |
video | |
videointelligence | |
videointelligence/apiv1 | Package videointelligence is an auto-generated package for the Cloud Video Intelligence API. |
videointelligence/apiv1beta2 | Package videointelligence is an auto-generated package for the Google Cloud Video Intelligence API. |
video/transcoder | |
video/transcoder/apiv1 | Package transcoder is an auto-generated package for the Transcoder API. |
video/transcoder/apiv1beta1 | Package transcoder is an auto-generated package for the Transcoder API. |
vision | |
vision/apiv1 | Package vision is an auto-generated package for the Cloud Vision API. |
vision/apiv1p1beta1 | Package vision is an auto-generated package for the Cloud Vision API. |
vpcaccess | |
vpcaccess/apiv1 | Package vpcaccess is an auto-generated package for the Serverless VPC Access API. |
webrisk | |
webrisk/apiv1 | Package webrisk is an auto-generated package for the Web Risk API. |
webrisk/apiv1beta1 | Package webrisk is an auto-generated package for the Web Risk API. |
websecurityscanner | |
websecurityscanner/apiv1 | Package websecurityscanner is an auto-generated package for the Web Security Scanner API. |
workflows | |
workflows/apiv1beta | Package workflows is an auto-generated package for the Workflows API. |
workflows/executions | |
workflows/executions/apiv1 | Package executions is an auto-generated package for the Workflow Executions API. |
workflows/executions/apiv1beta | Package executions is an auto-generated package for the Workflow Executions API. |
Tools for package owners.