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

Function ExampleTopic_ErrorAs

pubsub/example_test.go:203–224  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

201}
202
203func ExampleTopic_ErrorAs() {
204 // This example is specific to the gcppubsub implementation; it demonstrates
205 // access to the underlying Status type.
206 // The types exposed for As by gcppubsub are documented in
207 // https://godoc.org/gocloud.dev/pubsub/gcppubsub#hdr-As
208
209 ctx := context.Background()
210 topic, err := pubsub.OpenTopic(ctx, "gcppubsub://project/topic")
211 if err != nil {
212 log.Fatal(err)
213 }
214 defer topic.Shutdown(ctx)
215
216 err = topic.Send(ctx, &pubsub.Message{Body: []byte("hello")})
217 if err != nil {
218 var s *status.Status
219 if topic.ErrorAs(err, &s) {
220 _ = s.Code()
221 }
222 log.Fatal(err)
223 }
224}

Callers

nothing calls this directly

Calls 4

OpenTopicFunction · 0.92
SendMethod · 0.80
ShutdownMethod · 0.65
ErrorAsMethod · 0.65

Tested by

no test coverage detected