| 201 | } |
| 202 | |
| 203 | func 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 | } |