()
| 69 | } |
| 70 | |
| 71 | func ExampleOpenSubscription() { |
| 72 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |
| 73 | // PRAGMA: On gocloud.dev, hide lines until the next blank line. |
| 74 | ctx := context.Background() |
| 75 | |
| 76 | // Your GCP credentials. |
| 77 | // See https://cloud.google.com/docs/authentication/production |
| 78 | // for more info on alternatives. |
| 79 | creds, err := gcp.DefaultCredentials(ctx) |
| 80 | if err != nil { |
| 81 | log.Fatal(err) |
| 82 | } |
| 83 | |
| 84 | // Open a gRPC connection to the GCP Pub/Sub API. |
| 85 | // Alternatively, skip this and pass nil to Client below to use the default. |
| 86 | conn, cleanup, err := gcppubsubv2.Dial(ctx, creds.TokenSource) |
| 87 | if err != nil { |
| 88 | log.Fatal(err) |
| 89 | } |
| 90 | defer cleanup() |
| 91 | |
| 92 | // Construct a Client using the connection. |
| 93 | client, err := gcppubsubv2.Client(ctx, "myprojectID", conn) |
| 94 | if err != nil { |
| 95 | log.Fatal(err) |
| 96 | } |
| 97 | defer client.Close() |
| 98 | |
| 99 | // Construct a *pubsub.Subscription. |
| 100 | subscription := gcppubsubv2.OpenSubscription(client, "example-subscription", nil) |
| 101 | defer subscription.Shutdown(ctx) |
| 102 | } |
| 103 | |
| 104 | func Example_openSubscriptionFromURL() { |
| 105 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |
nothing calls this directly
no test coverage detected