1// Copyright 2021 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17package pubsub_test 18 19import ( 20 "context" 21 "io" 22 23 pubsub "cloud.google.com/go/pubsub/apiv1" 24 "google.golang.org/api/iterator" 25 pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 26) 27 28func ExampleNewSubscriberClient() { 29 ctx := context.Background() 30 c, err := pubsub.NewSubscriberClient(ctx) 31 if err != nil { 32 // TODO: Handle error. 33 } 34 // TODO: Use client. 35 _ = c 36} 37 38func ExampleSubscriberClient_CreateSubscription() { 39 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 40 41 ctx := context.Background() 42 c, err := pubsub.NewSubscriberClient(ctx) 43 if err != nil { 44 // TODO: Handle error. 45 } 46 47 req := &pubsubpb.Subscription{ 48 // TODO: Fill request struct fields. 49 } 50 resp, err := c.CreateSubscription(ctx, req) 51 if err != nil { 52 // TODO: Handle error. 53 } 54 // TODO: Use resp. 55 _ = resp 56} 57 58func ExampleSubscriberClient_GetSubscription() { 59 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 60 61 ctx := context.Background() 62 c, err := pubsub.NewSubscriberClient(ctx) 63 if err != nil { 64 // TODO: Handle error. 65 } 66 67 req := &pubsubpb.GetSubscriptionRequest{ 68 // TODO: Fill request struct fields. 69 } 70 resp, err := c.GetSubscription(ctx, req) 71 if err != nil { 72 // TODO: Handle error. 73 } 74 // TODO: Use resp. 75 _ = resp 76} 77 78func ExampleSubscriberClient_UpdateSubscription() { 79 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 80 81 ctx := context.Background() 82 c, err := pubsub.NewSubscriberClient(ctx) 83 if err != nil { 84 // TODO: Handle error. 85 } 86 87 req := &pubsubpb.UpdateSubscriptionRequest{ 88 // TODO: Fill request struct fields. 89 } 90 resp, err := c.UpdateSubscription(ctx, req) 91 if err != nil { 92 // TODO: Handle error. 93 } 94 // TODO: Use resp. 95 _ = resp 96} 97 98func ExampleSubscriberClient_ListSubscriptions() { 99 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 100 // import "google.golang.org/api/iterator" 101 102 ctx := context.Background() 103 c, err := pubsub.NewSubscriberClient(ctx) 104 if err != nil { 105 // TODO: Handle error. 106 } 107 108 req := &pubsubpb.ListSubscriptionsRequest{ 109 // TODO: Fill request struct fields. 110 } 111 it := c.ListSubscriptions(ctx, req) 112 for { 113 resp, err := it.Next() 114 if err == iterator.Done { 115 break 116 } 117 if err != nil { 118 // TODO: Handle error. 119 } 120 // TODO: Use resp. 121 _ = resp 122 } 123} 124 125func ExampleSubscriberClient_DeleteSubscription() { 126 ctx := context.Background() 127 c, err := pubsub.NewSubscriberClient(ctx) 128 if err != nil { 129 // TODO: Handle error. 130 } 131 132 req := &pubsubpb.DeleteSubscriptionRequest{ 133 // TODO: Fill request struct fields. 134 } 135 err = c.DeleteSubscription(ctx, req) 136 if err != nil { 137 // TODO: Handle error. 138 } 139} 140 141func ExampleSubscriberClient_ModifyAckDeadline() { 142 ctx := context.Background() 143 c, err := pubsub.NewSubscriberClient(ctx) 144 if err != nil { 145 // TODO: Handle error. 146 } 147 148 req := &pubsubpb.ModifyAckDeadlineRequest{ 149 // TODO: Fill request struct fields. 150 } 151 err = c.ModifyAckDeadline(ctx, req) 152 if err != nil { 153 // TODO: Handle error. 154 } 155} 156 157func ExampleSubscriberClient_Acknowledge() { 158 ctx := context.Background() 159 c, err := pubsub.NewSubscriberClient(ctx) 160 if err != nil { 161 // TODO: Handle error. 162 } 163 164 req := &pubsubpb.AcknowledgeRequest{ 165 // TODO: Fill request struct fields. 166 } 167 err = c.Acknowledge(ctx, req) 168 if err != nil { 169 // TODO: Handle error. 170 } 171} 172 173func ExampleSubscriberClient_Pull() { 174 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 175 176 ctx := context.Background() 177 c, err := pubsub.NewSubscriberClient(ctx) 178 if err != nil { 179 // TODO: Handle error. 180 } 181 182 req := &pubsubpb.PullRequest{ 183 // TODO: Fill request struct fields. 184 } 185 resp, err := c.Pull(ctx, req) 186 if err != nil { 187 // TODO: Handle error. 188 } 189 // TODO: Use resp. 190 _ = resp 191} 192 193func ExampleSubscriberClient_StreamingPull() { 194 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 195 196 ctx := context.Background() 197 c, err := pubsub.NewSubscriberClient(ctx) 198 if err != nil { 199 // TODO: Handle error. 200 } 201 stream, err := c.StreamingPull(ctx) 202 if err != nil { 203 // TODO: Handle error. 204 } 205 go func() { 206 reqs := []*pubsubpb.StreamingPullRequest{ 207 // TODO: Create requests. 208 } 209 for _, req := range reqs { 210 if err := stream.Send(req); err != nil { 211 // TODO: Handle error. 212 } 213 } 214 stream.CloseSend() 215 }() 216 for { 217 resp, err := stream.Recv() 218 if err == io.EOF { 219 break 220 } 221 if err != nil { 222 // TODO: handle error. 223 } 224 // TODO: Use resp. 225 _ = resp 226 } 227} 228 229func ExampleSubscriberClient_ModifyPushConfig() { 230 ctx := context.Background() 231 c, err := pubsub.NewSubscriberClient(ctx) 232 if err != nil { 233 // TODO: Handle error. 234 } 235 236 req := &pubsubpb.ModifyPushConfigRequest{ 237 // TODO: Fill request struct fields. 238 } 239 err = c.ModifyPushConfig(ctx, req) 240 if err != nil { 241 // TODO: Handle error. 242 } 243} 244 245func ExampleSubscriberClient_GetSnapshot() { 246 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 247 248 ctx := context.Background() 249 c, err := pubsub.NewSubscriberClient(ctx) 250 if err != nil { 251 // TODO: Handle error. 252 } 253 254 req := &pubsubpb.GetSnapshotRequest{ 255 // TODO: Fill request struct fields. 256 } 257 resp, err := c.GetSnapshot(ctx, req) 258 if err != nil { 259 // TODO: Handle error. 260 } 261 // TODO: Use resp. 262 _ = resp 263} 264 265func ExampleSubscriberClient_ListSnapshots() { 266 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 267 // import "google.golang.org/api/iterator" 268 269 ctx := context.Background() 270 c, err := pubsub.NewSubscriberClient(ctx) 271 if err != nil { 272 // TODO: Handle error. 273 } 274 275 req := &pubsubpb.ListSnapshotsRequest{ 276 // TODO: Fill request struct fields. 277 } 278 it := c.ListSnapshots(ctx, req) 279 for { 280 resp, err := it.Next() 281 if err == iterator.Done { 282 break 283 } 284 if err != nil { 285 // TODO: Handle error. 286 } 287 // TODO: Use resp. 288 _ = resp 289 } 290} 291 292func ExampleSubscriberClient_CreateSnapshot() { 293 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 294 295 ctx := context.Background() 296 c, err := pubsub.NewSubscriberClient(ctx) 297 if err != nil { 298 // TODO: Handle error. 299 } 300 301 req := &pubsubpb.CreateSnapshotRequest{ 302 // TODO: Fill request struct fields. 303 } 304 resp, err := c.CreateSnapshot(ctx, req) 305 if err != nil { 306 // TODO: Handle error. 307 } 308 // TODO: Use resp. 309 _ = resp 310} 311 312func ExampleSubscriberClient_UpdateSnapshot() { 313 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 314 315 ctx := context.Background() 316 c, err := pubsub.NewSubscriberClient(ctx) 317 if err != nil { 318 // TODO: Handle error. 319 } 320 321 req := &pubsubpb.UpdateSnapshotRequest{ 322 // TODO: Fill request struct fields. 323 } 324 resp, err := c.UpdateSnapshot(ctx, req) 325 if err != nil { 326 // TODO: Handle error. 327 } 328 // TODO: Use resp. 329 _ = resp 330} 331 332func ExampleSubscriberClient_DeleteSnapshot() { 333 ctx := context.Background() 334 c, err := pubsub.NewSubscriberClient(ctx) 335 if err != nil { 336 // TODO: Handle error. 337 } 338 339 req := &pubsubpb.DeleteSnapshotRequest{ 340 // TODO: Fill request struct fields. 341 } 342 err = c.DeleteSnapshot(ctx, req) 343 if err != nil { 344 // TODO: Handle error. 345 } 346} 347 348func ExampleSubscriberClient_Seek() { 349 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 350 351 ctx := context.Background() 352 c, err := pubsub.NewSubscriberClient(ctx) 353 if err != nil { 354 // TODO: Handle error. 355 } 356 357 req := &pubsubpb.SeekRequest{ 358 // TODO: Fill request struct fields. 359 } 360 resp, err := c.Seek(ctx, req) 361 if err != nil { 362 // TODO: Handle error. 363 } 364 // TODO: Use resp. 365 _ = resp 366} 367