()
| 27 | ) |
| 28 | |
| 29 | func ExampleOpenTopic() { |
| 30 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |
| 31 | // PRAGMA: On gocloud.dev, hide lines until the next blank line. |
| 32 | ctx := context.Background() |
| 33 | |
| 34 | // Your GCP credentials. |
| 35 | // See https://cloud.google.com/docs/authentication/production |
| 36 | // for more info on alternatives. |
| 37 | creds, err := gcp.DefaultCredentials(ctx) |
| 38 | if err != nil { |
| 39 | log.Fatal(err) |
| 40 | } |
| 41 | // Open a gRPC connection to the GCP Pub/Sub API. |
| 42 | conn, cleanup, err := gcppubsub.Dial(ctx, creds.TokenSource) |
| 43 | if err != nil { |
| 44 | log.Fatal(err) |
| 45 | } |
| 46 | defer cleanup() |
| 47 | |
| 48 | // Construct a PublisherClient using the connection. |
| 49 | pubClient, err := gcppubsub.PublisherClient(ctx, conn) |
| 50 | if err != nil { |
| 51 | log.Fatal(err) |
| 52 | } |
| 53 | defer pubClient.Close() |
| 54 | |
| 55 | // Construct a *pubsub.Topic. |
| 56 | topic, err := gcppubsub.OpenTopicByPath(pubClient, "projects/myprojectID/topics/example-topic", nil) |
| 57 | if err != nil { |
| 58 | log.Fatal(err) |
| 59 | } |
| 60 | defer topic.Shutdown(ctx) |
| 61 | } |
| 62 | |
| 63 | func Example_openTopicFromURL() { |
| 64 | // 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