14
14
15
15
/*
16
16
Package cloud is the root of the packages used to access Google Cloud
17
- Services. See https://godoc.org /cloud.google.com/go for a full list
18
- of sub-packages .
17
+ Services. See https://pkg.go.dev /cloud.google.com/go for a full list
18
+ of sub-modules .
19
19
20
20
# Client Options
21
21
22
- All clients in sub-packages are configurable via client options. These options are
23
- described here: https://godoc.org /google.golang.org/api/option.
22
+ All clients in sub-packages are configurable via client options. These options
23
+ are described here: https://pkg.go.dev /google.golang.org/api/option.
24
24
25
- ## Endpoint Override
25
+ # Endpoint Override
26
26
27
27
Endpoint configuration is used to specify the URL to which requests are
28
- sent. It is used for services that support or require regional endpoints, as well
29
- as for other use cases such as [testing against fake
30
- servers](https://github.com/googleapis/google-cloud-go/blob/main/testing.md#testing-grpc-services-using-fakes).
28
+ sent. It is used for services that support or require regional endpoints, as
29
+ well as for other use cases such as [testing against fake servers].
31
30
32
- For example, the Vertex AI service recommends that you configure the endpoint to the
33
- location with the features you want that is closest to your physical location or the
34
- location of your users. There is no global endpoint for Vertex AI. See
35
- [Vertex AI - Locations](https://cloud.google.com/vertex-ai/docs/general/locations)
36
- for more details. The following example demonstrates configuring a Vertex AI client
37
- with a regional endpoint:
31
+ For example, the Vertex AI service recommends that you configure the endpoint to
32
+ the location with the features you want that is closest to your physical
33
+ location or the location of your users. There is no global endpoint for Vertex
34
+ AI. See [Vertex AI - Locations] for more details. The following example
35
+ demonstrates configuring a Vertex AI client with a regional endpoint:
38
36
39
37
ctx := context.Background()
40
38
endpoint := "us-central1-aiplatform.googleapis.com:443"
41
39
client, err := aiplatform.NewDatasetClient(ctx, option.WithEndpoint(endpoint))
42
40
43
41
# Authentication and Authorization
44
42
45
- All the clients in sub-packages support authentication via Google Application Default
46
- Credentials (see https://cloud.google.com/docs/authentication/production), or
47
- by providing a JSON key file for a Service Account. See examples below.
43
+ All of the clients support authentication via [Google Application Default Credentials],
44
+ or by providing a JSON key file for a Service Account. See examples below.
48
45
49
46
Google Application Default Credentials (ADC) is the recommended way to authorize
50
47
and authenticate clients. For information on how to create and obtain
51
48
Application Default Credentials, see
52
- https://cloud.google.com/docs/authentication/production. Here is an example
53
- of a client using ADC to authenticate:
49
+ https://cloud.google.com/docs/authentication/production. If you have your
50
+ environment configured correctly you will not need to pass any extra information
51
+ to the client libraries. Here is an example of a client using ADC to
52
+ authenticate:
54
53
55
54
client, err := secretmanager.NewClient(context.Background())
56
55
if err != nil {
57
56
// TODO: handle error.
58
57
}
59
58
_ = client // Use the client.
60
59
61
- You can use a file with credentials to authenticate and authorize, such as a JSON
62
- key file associated with a Google service account. Service Account keys can be
63
- created and downloaded from
64
- https://console.cloud.google.com/iam-admin/serviceaccounts. This example uses
65
- the Secret Manger client, but the same steps apply to the other client libraries
66
- underneath this package. Example:
60
+ You can use a file with credentials to authenticate and authorize, such as a
61
+ JSON key file associated with a Google service account. Service Account keys can
62
+ be created and downloaded from https://console.cloud.google.com/iam-admin/serviceaccounts.
63
+ This example uses the Secret Manger client, but the same steps apply to the
64
+ all other client libraries this package as well. Example:
67
65
68
66
client, err := secretmanager.NewClient(context.Background(),
69
67
option.WithCredentialsFile("/path/to/service-account-key.json"))
@@ -74,14 +72,14 @@ underneath this package. Example:
74
72
75
73
In some cases (for instance, you don't want to store secrets on disk), you can
76
74
create credentials from in-memory JSON and use the WithCredentials option.
77
- The google package in this example is at golang.org/x/oauth2/google.
78
75
This example uses the Secret Manager client, but the same steps apply to
79
- the other client libraries underneath this package . Note that scopes can be
76
+ all other client libraries as well . Note that scopes can be
80
77
found at https://developers.google.com/identity/protocols/oauth2/scopes, and
81
78
are also provided in all auto-generated libraries: for example,
82
79
cloud.google.com/go/secretmanager/apiv1 provides DefaultAuthScopes. Example:
83
80
84
81
ctx := context.Background()
82
+ // https://pkg.go.dev/golang.org/x/oauth2/google
85
83
creds, err := google.CredentialsFromJSON(ctx, []byte("JSON creds"), secretmanager.DefaultAuthScopes()...)
86
84
if err != nil {
87
85
// TODO: handle error.
@@ -97,10 +95,11 @@ cloud.google.com/go/secretmanager/apiv1 provides DefaultAuthScopes. Example:
97
95
By default, non-streaming methods, like Create or Get, will have a default
98
96
deadline applied to the context provided at call time, unless a context deadline
99
97
is already set. Streaming methods have no default deadline and will run
100
- indefinitely. To set timeouts or arrange for cancellation, use contexts.
101
- Transient errors will be retried when correctness allows.
98
+ indefinitely. To set timeouts or arrange for cancellation, use
99
+ [context]. Transient errors will be retried when correctness allows.
102
100
103
- Here is an example of setting a timeout for an RPC using context.WithTimeout:
101
+ Here is an example of setting a timeout for an RPC using
102
+ [context.WithTimeout]:
104
103
105
104
ctx := context.Background()
106
105
// Do not set a timeout on the context passed to NewClient: dialing happens
@@ -119,7 +118,8 @@ Here is an example of setting a timeout for an RPC using context.WithTimeout:
119
118
// TODO: handle error.
120
119
}
121
120
122
- Here is an example of setting a timeout for an RPC using gax.WithTimeout:
121
+ Here is an example of setting a timeout for an RPC using
122
+ [github.com/googleapis/gax-go/v2.WithTimeout]:
123
123
124
124
ctx := context.Background()
125
125
// Do not set a timeout on the context passed to NewClient: dialing happens
@@ -136,7 +136,8 @@ Here is an example of setting a timeout for an RPC using gax.WithTimeout:
136
136
// TODO: handle error.
137
137
}
138
138
139
- Here is an example of how to arrange for an RPC to be canceled, use context.WithCancel:
139
+ Here is an example of how to arrange for an RPC to be canceled, use
140
+ [context.WithCancel]:
140
141
141
142
ctx := context.Background()
142
143
// Do not cancel the context passed to NewClient: dialing happens asynchronously,
@@ -155,53 +156,53 @@ Here is an example of how to arrange for an RPC to be canceled, use context.With
155
156
// TODO: handle error.
156
157
}
157
158
158
- Do not attempt to control the initial connection (dialing) of a service by setting a
159
- timeout on the context passed to NewClient. Dialing is non-blocking, so timeouts
160
- would be ineffective and would only interfere with credential refreshing, which uses
161
- the same context.
159
+ Do not attempt to control the initial connection (dialing) of a service by
160
+ setting a timeout on the context passed to NewClient. Dialing is non-blocking,
161
+ so timeouts would be ineffective and would only interfere with credential
162
+ refreshing, which uses the same context.
162
163
163
164
# Connection Pooling
164
165
165
166
Connection pooling differs in clients based on their transport. Cloud
166
167
clients either rely on HTTP or gRPC transports to communicate
167
168
with Google Cloud.
168
169
169
- Cloud clients that use HTTP (bigquery, compute, storage, and translate) rely on the
170
- underlying HTTP transport to cache connections for later re-use. These are cached to
171
- the default http.MaxIdleConns and http.MaxIdleConnsPerHost settings in
172
- http.DefaultTransport.
170
+ Cloud clients that use HTTP rely on the underlying HTTP transport to cache
171
+ connections for later re-use. These are cached to the http.MaxIdleConns
172
+ and http.MaxIdleConnsPerHost settings in http.DefaultTransport by default.
173
173
174
- For gRPC clients (all others in this repo) , connection pooling is configurable. Users
175
- of cloud client libraries may specify option.WithGRPCConnectionPool(n) as a client
176
- option to NewClient calls. This configures the underlying gRPC connections to be
177
- pooled and addressed in a round robin fashion.
174
+ For gRPC clients, connection pooling is configurable. Users of Cloud Client
175
+ Libraries may specify option.WithGRPCConnectionPool(n) as a client option to
176
+ NewClient calls. This configures the underlying gRPC connections to be pooled
177
+ and accessed in a round robin fashion.
178
178
179
- # Using the Libraries with Docker
179
+ # Using the Libraries in Container environments( Docker)
180
180
181
- Minimal docker images like Alpine lack CA certificates. This causes RPCs to appear to
182
- hang, because gRPC retries indefinitely. See https://github.com/googleapis/google-cloud-go/issues/928
183
- for more information.
181
+ Minimal container images like Alpine lack CA certificates. This causes RPCs to
182
+ appear to hang, because gRPC retries indefinitely. See
183
+ https://github.com/googleapis/google-cloud-go/issues/928 for more information.
184
184
185
185
# Debugging
186
186
187
- To see gRPC logs, set the environment variable GRPC_GO_LOG_SEVERITY_LEVEL. See
188
- https://godoc.org/google.golang.org/grpc/grpclog for more information .
187
+ For tips on how to write tests against code that calls into our libraries check
188
+ out our [Debugging Guide] .
189
189
190
- For HTTP logging, set the GODEBUG environment variable to "http2debug=1" or "http2debug=2".
190
+ # Testing
191
+
192
+ For tips on how to write tests against code that calls into our libraries check
193
+ out our [Testing Guide].
191
194
192
195
# Inspecting errors
193
196
194
197
Most of the errors returned by the generated clients are wrapped in an
195
198
[github.com/googleapis/gax-go/v2/apierror.APIError] and can be further unwrapped
196
199
into a [google.golang.org/grpc/status.Status] or
197
- [google.golang.org/api/googleapi.Error] depending
198
- on the transport used to make the call (gRPC or REST). Converting your errors to
199
- these types can be a useful way to get more information about what went wrong
200
- while debugging.
200
+ [google.golang.org/api/googleapi.Error] depending on the transport used to make
201
+ the call (gRPC or REST). Converting your errors to these types can be a useful
202
+ way to get more information about what went wrong while debugging.
201
203
202
- [github.com/googleapis/gax-go/v2/apierror.APIError] gives access to specific
203
- details in the error. The transport-specific errors can still be unwrapped using
204
- the [github.com/googleapis/gax-go/v2/apierror.APIError].
204
+ APIError gives access to specific details in the error. The transport-specific
205
+ errors can still be unwrapped using the APIError.
205
206
206
207
if err != nil {
207
208
var ae *apierror.APIError
@@ -223,36 +224,33 @@ still be parsed using the [google.golang.org/grpc/status.FromError] function.
223
224
}
224
225
}
225
226
226
- If the REST transport was used, the [google.golang.org/api/googleapi.Error] can
227
- be parsed in a similar way, allowing access to details such as the HTTP response
228
- code.
229
-
230
- if err != nil {
231
- var gerr *googleapi.Error
232
- if errors.As(err, &gerr) {
233
- log.Println(gerr.Message)
234
- }
235
- }
236
-
237
227
# Client Stability
238
228
239
- Clients in this repository are considered alpha or beta unless otherwise
240
- marked as stable in the README.md. Semver is not used to communicate stability
241
- of clients.
229
+ Semver is used to communicate stability of the sub-modules of this package.
230
+ Note, some stable sub-modules do contain packages, and sometimes features, that
231
+ are considered unstable. If something is unstable it will be explicitly labeled
232
+ as such. Example of package does in an unstable package:
233
+
234
+ NOTE: This package is in beta. It is not stable, and may be subject to changes.
242
235
243
- Alpha and beta clients may change or go away without notice.
236
+ Clients that contain alpha and beta in their import path may change or go away
237
+ without notice.
244
238
245
239
Clients marked stable will maintain compatibility with future versions for as
246
240
long as we can reasonably sustain. Incompatible changes might be made in some
247
241
situations, including:
248
242
249
- - Security bugs may prompt backwards-incompatible changes.
250
-
251
- - Situations in which components are no longer feasible to maintain without
252
- making breaking changes, including removal.
253
-
254
- - Parts of the client surface may be outright unstable and subject to change.
255
- These parts of the surface will be labeled with the note, "It is EXPERIMENTAL
256
- and subject to change or removal without notice."
243
+ - Security bugs may prompt backwards-incompatible changes.
244
+ - Situations in which components are no longer feasible to maintain without
245
+ making breaking changes, including removal.
246
+ - Parts of the client surface may be outright unstable and subject to change.
247
+ These parts of the surface will be labeled with the note, "It is EXPERIMENTAL
248
+ and subject to change or removal without notice."
249
+
250
+ [testing against fake servers]: https://github.com/googleapis/google-cloud-go/blob/main/testing.md#testing-grpc-services-using-fakes
251
+ [Vertex AI - Locations]: https://cloud.google.com/vertex-ai/docs/general/locations
252
+ [Google Application Default Credentials]: https://cloud.google.com/docs/authentication/external/set-up-adc
253
+ [Debugging Guide]: https://github.com/googleapis/google-cloud-go/blob/main/debug.md
254
+ [Testing Guide]: https://github.com/googleapis/google-cloud-go/blob/main/testing.md
257
255
*/
258
256
package cloud // import "cloud.google.com/go"
0 commit comments