MCPcopy Create free account
hub / github.com/google/go-cloud / ExampleOpenBucket

Function ExampleOpenBucket

blob/gcsblob/example_test.go:26–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24)
25
26func ExampleOpenBucket() {
27 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
28 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
29 ctx := context.Background()
30
31 // Your GCP credentials.
32 // See https://cloud.google.com/docs/authentication/production
33 // for more info on alternatives.
34 creds, err := gcp.DefaultCredentials(ctx)
35 if err != nil {
36 log.Fatal(err)
37 }
38
39 // Create an HTTP client.
40 // This example uses the default HTTP transport and the credentials
41 // created above.
42 client, err := gcp.NewHTTPClient(
43 gcp.DefaultTransport(),
44 gcp.CredentialsTokenSource(creds))
45 if err != nil {
46 log.Fatal(err)
47 }
48
49 // Create a *blob.Bucket.
50 bucket, err := gcsblob.OpenBucket(ctx, client, "my-bucket", nil)
51 if err != nil {
52 log.Fatal(err)
53 }
54 defer bucket.Close()
55}
56
57func Example_openBucketFromURL() {
58 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.

Callers

nothing calls this directly

Calls 6

DefaultCredentialsFunction · 0.92
NewHTTPClientFunction · 0.92
DefaultTransportFunction · 0.92
CredentialsTokenSourceFunction · 0.92
OpenBucketFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected