Skip to content

Commit c401ab4

Browse files
authored
fix: add more docs to base package (#8274)
Tweaking and adding some more docs to our base package docs. We have gotten some feedback that our individual clients don't contain some of this cross-client information so bolstering these docs before making a generator PR to link to them. Also updated some styling for 1.19+. Related internal bugs: 288887575, 288883068, 288883059
1 parent 5b288b5 commit c401ab4

File tree

1 file changed

+79
-81
lines changed

1 file changed

+79
-81
lines changed

doc.go

+79-81
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,54 @@
1414

1515
/*
1616
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.
1919
2020
# Client Options
2121
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.
2424
25-
## Endpoint Override
25+
# Endpoint Override
2626
2727
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].
3130
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:
3836
3937
ctx := context.Background()
4038
endpoint := "us-central1-aiplatform.googleapis.com:443"
4139
client, err := aiplatform.NewDatasetClient(ctx, option.WithEndpoint(endpoint))
4240
4341
# Authentication and Authorization
4442
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.
4845
4946
Google Application Default Credentials (ADC) is the recommended way to authorize
5047
and authenticate clients. For information on how to create and obtain
5148
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:
5453
5554
client, err := secretmanager.NewClient(context.Background())
5655
if err != nil {
5756
// TODO: handle error.
5857
}
5958
_ = client // Use the client.
6059
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:
6765
6866
client, err := secretmanager.NewClient(context.Background(),
6967
option.WithCredentialsFile("/path/to/service-account-key.json"))
@@ -74,14 +72,14 @@ underneath this package. Example:
7472
7573
In some cases (for instance, you don't want to store secrets on disk), you can
7674
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.
7875
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
8077
found at https://developers.google.com/identity/protocols/oauth2/scopes, and
8178
are also provided in all auto-generated libraries: for example,
8279
cloud.google.com/go/secretmanager/apiv1 provides DefaultAuthScopes. Example:
8380
8481
ctx := context.Background()
82+
// https://pkg.go.dev/golang.org/x/oauth2/google
8583
creds, err := google.CredentialsFromJSON(ctx, []byte("JSON creds"), secretmanager.DefaultAuthScopes()...)
8684
if err != nil {
8785
// TODO: handle error.
@@ -97,10 +95,11 @@ cloud.google.com/go/secretmanager/apiv1 provides DefaultAuthScopes. Example:
9795
By default, non-streaming methods, like Create or Get, will have a default
9896
deadline applied to the context provided at call time, unless a context deadline
9997
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.
102100
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]:
104103
105104
ctx := context.Background()
106105
// 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:
119118
// TODO: handle error.
120119
}
121120
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]:
123123
124124
ctx := context.Background()
125125
// 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:
136136
// TODO: handle error.
137137
}
138138
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]:
140141
141142
ctx := context.Background()
142143
// 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
155156
// TODO: handle error.
156157
}
157158
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.
162163
163164
# Connection Pooling
164165
165166
Connection pooling differs in clients based on their transport. Cloud
166167
clients either rely on HTTP or gRPC transports to communicate
167168
with Google Cloud.
168169
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.
173173
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.
178178
179-
# Using the Libraries with Docker
179+
# Using the Libraries in Container environments(Docker)
180180
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.
184184
185185
# Debugging
186186
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].
189189
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].
191194
192195
# Inspecting errors
193196
194197
Most of the errors returned by the generated clients are wrapped in an
195198
[github.com/googleapis/gax-go/v2/apierror.APIError] and can be further unwrapped
196199
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.
201203
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.
205206
206207
if err != nil {
207208
var ae *apierror.APIError
@@ -223,36 +224,33 @@ still be parsed using the [google.golang.org/grpc/status.FromError] function.
223224
}
224225
}
225226
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-
237227
# Client Stability
238228
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.
242235
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.
244238
245239
Clients marked stable will maintain compatibility with future versions for as
246240
long as we can reasonably sustain. Incompatible changes might be made in some
247241
situations, including:
248242
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
257255
*/
258256
package cloud // import "cloud.google.com/go"

0 commit comments

Comments
 (0)