MCPcopy Index your code
hub / github.com/google/go-cloud / ExampleSubscription_ErrorAs

Function ExampleSubscription_ErrorAs

pubsub/example_test.go:160–182  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

158}
159
160func ExampleSubscription_ErrorAs() {
161 // This example is specific to the gcppubsub implementation; it demonstrates
162 // access to the underlying Status type.
163 // The types exposed for As by gcppubsub are documented in
164 // https://godoc.org/gocloud.dev/pubsub/gcppubsub#hdr-As
165
166 ctx := context.Background()
167 sub, err := pubsub.OpenSubscription(ctx, "gcppubsub://project/badtopic")
168 if err != nil {
169 log.Fatal(err)
170 }
171 defer sub.Shutdown(ctx)
172
173 msg, err := sub.Receive(ctx)
174 if err != nil {
175 var s *status.Status
176 if sub.ErrorAs(err, &s) {
177 _ = s.Code()
178 }
179 log.Fatal(err)
180 }
181 msg.Ack()
182}
183
184func ExampleTopic_As() {
185 // This example is specific to the gcppubsub implementation; it demonstrates

Callers

nothing calls this directly

Calls 5

OpenSubscriptionFunction · 0.92
ReceiveMethod · 0.80
ShutdownMethod · 0.65
ErrorAsMethod · 0.65
AckMethod · 0.65

Tested by

no test coverage detected