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

Function ExampleMessage_As

pubsub/example_test.go:117–139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

115}
116
117func ExampleMessage_As() {
118 // This example is specific to the gcppubsub implementation; it demonstrates
119 // access to the underlying PubsubMessage type.
120 // The types exposed for As by gcppubsub are documented in
121 // https://godoc.org/gocloud.dev/pubsub/gcppubsub#hdr-As
122
123 ctx := context.Background()
124 sub, err := pubsub.OpenSubscription(ctx, "gcppubsub://project/topic")
125 if err != nil {
126 log.Fatal(err)
127 }
128 defer sub.Shutdown(ctx)
129
130 msg, err := sub.Receive(ctx)
131 if err != nil {
132 log.Fatal(err)
133 }
134 var pm *pbapi.PubsubMessage
135 if msg.As(&pm) {
136 _ = pm.GetAttributes()
137 }
138 msg.Ack()
139}
140
141func ExampleSubscription_As() {
142 // 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
AsMethod · 0.65
AckMethod · 0.65

Tested by

no test coverage detected