Debian Codegraph @

pubsub/v2/apiv1/topic_admin_client_example_test.go

raw
1 // Copyright 2025 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
17 package pubsub_test
18
19 import (
20 "context"
21
22 iampb "cloud.google.com/go/iam/apiv1/iampb"
23 pubsub "cloud.google.com/go/pubsub/v2/apiv1"
24 pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
25 "google.golang.org/api/iterator"
26 )
27
28 func ExampleNewTopicAdminClient() {
29 ctx := context.Background()
30 // This snippet has been automatically generated and should be regarded as a code template only.
31 // It will require modifications to work:
32 // - It may require correct/in-range values for request initialization.
33 // - It may require specifying regional endpoints when creating the service client as shown in:
34 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
35 c, err := pubsub.NewTopicAdminClient(ctx)
36 if err != nil {
37 // TODO: Handle error.
38 }
39 defer c.Close()
40
41 // TODO: Use client.
42 _ = c
43 }
44
45 func ExampleNewTopicAdminRESTClient() {
46 ctx := context.Background()
47 // This snippet has been automatically generated and should be regarded as a code template only.
48 // It will require modifications to work:
49 // - It may require correct/in-range values for request initialization.
50 // - It may require specifying regional endpoints when creating the service client as shown in:
51 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
52 c, err := pubsub.NewTopicAdminRESTClient(ctx)
53 if err != nil {
54 // TODO: Handle error.
55 }
56 defer c.Close()
57
58 // TODO: Use client.
59 _ = c
60 }
61
62 func ExampleTopicAdminClient_CreateTopic() {
63 ctx := context.Background()
64 // This snippet has been automatically generated and should be regarded as a code template only.
65 // It will require modifications to work:
66 // - It may require correct/in-range values for request initialization.
67 // - It may require specifying regional endpoints when creating the service client as shown in:
68 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
69 c, err := pubsub.NewTopicAdminClient(ctx)
70 if err != nil {
71 // TODO: Handle error.
72 }
73 defer c.Close()
74
75 req := &pubsubpb.Topic{
76 // TODO: Fill request struct fields.
77 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#Topic.
78 }
79 resp, err := c.CreateTopic(ctx, req)
80 if err != nil {
81 // TODO: Handle error.
82 }
83 // TODO: Use resp.
84 _ = resp
85 }
86
87 func ExampleTopicAdminClient_DeleteTopic() {
88 ctx := context.Background()
89 // This snippet has been automatically generated and should be regarded as a code template only.
90 // It will require modifications to work:
91 // - It may require correct/in-range values for request initialization.
92 // - It may require specifying regional endpoints when creating the service client as shown in:
93 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
94 c, err := pubsub.NewTopicAdminClient(ctx)
95 if err != nil {
96 // TODO: Handle error.
97 }
98 defer c.Close()
99
100 req := &pubsubpb.DeleteTopicRequest{
101 // TODO: Fill request struct fields.
102 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteTopicRequest.
103 }
104 err = c.DeleteTopic(ctx, req)
105 if err != nil {
106 // TODO: Handle error.
107 }
108 }
109
110 func ExampleTopicAdminClient_DetachSubscription() {
111 ctx := context.Background()
112 // This snippet has been automatically generated and should be regarded as a code template only.
113 // It will require modifications to work:
114 // - It may require correct/in-range values for request initialization.
115 // - It may require specifying regional endpoints when creating the service client as shown in:
116 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
117 c, err := pubsub.NewTopicAdminClient(ctx)
118 if err != nil {
119 // TODO: Handle error.
120 }
121 defer c.Close()
122
123 req := &pubsubpb.DetachSubscriptionRequest{
124 // TODO: Fill request struct fields.
125 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DetachSubscriptionRequest.
126 }
127 resp, err := c.DetachSubscription(ctx, req)
128 if err != nil {
129 // TODO: Handle error.
130 }
131 // TODO: Use resp.
132 _ = resp
133 }
134
135 func ExampleTopicAdminClient_GetTopic() {
136 ctx := context.Background()
137 // This snippet has been automatically generated and should be regarded as a code template only.
138 // It will require modifications to work:
139 // - It may require correct/in-range values for request initialization.
140 // - It may require specifying regional endpoints when creating the service client as shown in:
141 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
142 c, err := pubsub.NewTopicAdminClient(ctx)
143 if err != nil {
144 // TODO: Handle error.
145 }
146 defer c.Close()
147
148 req := &pubsubpb.GetTopicRequest{
149 // TODO: Fill request struct fields.
150 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#GetTopicRequest.
151 }
152 resp, err := c.GetTopic(ctx, req)
153 if err != nil {
154 // TODO: Handle error.
155 }
156 // TODO: Use resp.
157 _ = resp
158 }
159
160 func ExampleTopicAdminClient_ListTopicSnapshots() {
161 ctx := context.Background()
162 // This snippet has been automatically generated and should be regarded as a code template only.
163 // It will require modifications to work:
164 // - It may require correct/in-range values for request initialization.
165 // - It may require specifying regional endpoints when creating the service client as shown in:
166 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
167 c, err := pubsub.NewTopicAdminClient(ctx)
168 if err != nil {
169 // TODO: Handle error.
170 }
171 defer c.Close()
172
173 req := &pubsubpb.ListTopicSnapshotsRequest{
174 // TODO: Fill request struct fields.
175 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicSnapshotsRequest.
176 }
177 it := c.ListTopicSnapshots(ctx, req)
178 for {
179 resp, err := it.Next()
180 if err == iterator.Done {
181 break
182 }
183 if err != nil {
184 // TODO: Handle error.
185 }
186 // TODO: Use resp.
187 _ = resp
188
189 // If you need to access the underlying RPC response,
190 // you can do so by casting the `Response` as below.
191 // Otherwise, remove this line. Only populated after
192 // first call to Next(). Not safe for concurrent access.
193 _ = it.Response.(*pubsubpb.ListTopicSnapshotsResponse)
194 }
195 }
196
197 func ExampleTopicAdminClient_ListTopicSubscriptions() {
198 ctx := context.Background()
199 // This snippet has been automatically generated and should be regarded as a code template only.
200 // It will require modifications to work:
201 // - It may require correct/in-range values for request initialization.
202 // - It may require specifying regional endpoints when creating the service client as shown in:
203 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
204 c, err := pubsub.NewTopicAdminClient(ctx)
205 if err != nil {
206 // TODO: Handle error.
207 }
208 defer c.Close()
209
210 req := &pubsubpb.ListTopicSubscriptionsRequest{
211 // TODO: Fill request struct fields.
212 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicSubscriptionsRequest.
213 }
214 it := c.ListTopicSubscriptions(ctx, req)
215 for {
216 resp, err := it.Next()
217 if err == iterator.Done {
218 break
219 }
220 if err != nil {
221 // TODO: Handle error.
222 }
223 // TODO: Use resp.
224 _ = resp
225
226 // If you need to access the underlying RPC response,
227 // you can do so by casting the `Response` as below.
228 // Otherwise, remove this line. Only populated after
229 // first call to Next(). Not safe for concurrent access.
230 _ = it.Response.(*pubsubpb.ListTopicSubscriptionsResponse)
231 }
232 }
233
234 func ExampleTopicAdminClient_ListTopics() {
235 ctx := context.Background()
236 // This snippet has been automatically generated and should be regarded as a code template only.
237 // It will require modifications to work:
238 // - It may require correct/in-range values for request initialization.
239 // - It may require specifying regional endpoints when creating the service client as shown in:
240 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
241 c, err := pubsub.NewTopicAdminClient(ctx)
242 if err != nil {
243 // TODO: Handle error.
244 }
245 defer c.Close()
246
247 req := &pubsubpb.ListTopicsRequest{
248 // TODO: Fill request struct fields.
249 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicsRequest.
250 }
251 it := c.ListTopics(ctx, req)
252 for {
253 resp, err := it.Next()
254 if err == iterator.Done {
255 break
256 }
257 if err != nil {
258 // TODO: Handle error.
259 }
260 // TODO: Use resp.
261 _ = resp
262
263 // If you need to access the underlying RPC response,
264 // you can do so by casting the `Response` as below.
265 // Otherwise, remove this line. Only populated after
266 // first call to Next(). Not safe for concurrent access.
267 _ = it.Response.(*pubsubpb.ListTopicsResponse)
268 }
269 }
270
271 func ExampleTopicAdminClient_Publish() {
272 ctx := context.Background()
273 // This snippet has been automatically generated and should be regarded as a code template only.
274 // It will require modifications to work:
275 // - It may require correct/in-range values for request initialization.
276 // - It may require specifying regional endpoints when creating the service client as shown in:
277 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
278 c, err := pubsub.NewTopicAdminClient(ctx)
279 if err != nil {
280 // TODO: Handle error.
281 }
282 defer c.Close()
283
284 req := &pubsubpb.PublishRequest{
285 // TODO: Fill request struct fields.
286 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#PublishRequest.
287 }
288 resp, err := c.Publish(ctx, req)
289 if err != nil {
290 // TODO: Handle error.
291 }
292 // TODO: Use resp.
293 _ = resp
294 }
295
296 func ExampleTopicAdminClient_UpdateTopic() {
297 ctx := context.Background()
298 // This snippet has been automatically generated and should be regarded as a code template only.
299 // It will require modifications to work:
300 // - It may require correct/in-range values for request initialization.
301 // - It may require specifying regional endpoints when creating the service client as shown in:
302 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
303 c, err := pubsub.NewTopicAdminClient(ctx)
304 if err != nil {
305 // TODO: Handle error.
306 }
307 defer c.Close()
308
309 req := &pubsubpb.UpdateTopicRequest{
310 // TODO: Fill request struct fields.
311 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#UpdateTopicRequest.
312 }
313 resp, err := c.UpdateTopic(ctx, req)
314 if err != nil {
315 // TODO: Handle error.
316 }
317 // TODO: Use resp.
318 _ = resp
319 }
320
321 func ExampleTopicAdminClient_GetIamPolicy() {
322 ctx := context.Background()
323 // This snippet has been automatically generated and should be regarded as a code template only.
324 // It will require modifications to work:
325 // - It may require correct/in-range values for request initialization.
326 // - It may require specifying regional endpoints when creating the service client as shown in:
327 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
328 c, err := pubsub.NewTopicAdminClient(ctx)
329 if err != nil {
330 // TODO: Handle error.
331 }
332 defer c.Close()
333
334 req := &iampb.GetIamPolicyRequest{
335 // TODO: Fill request struct fields.
336 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
337 }
338 resp, err := c.GetIamPolicy(ctx, req)
339 if err != nil {
340 // TODO: Handle error.
341 }
342 // TODO: Use resp.
343 _ = resp
344 }
345
346 func ExampleTopicAdminClient_SetIamPolicy() {
347 ctx := context.Background()
348 // This snippet has been automatically generated and should be regarded as a code template only.
349 // It will require modifications to work:
350 // - It may require correct/in-range values for request initialization.
351 // - It may require specifying regional endpoints when creating the service client as shown in:
352 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
353 c, err := pubsub.NewTopicAdminClient(ctx)
354 if err != nil {
355 // TODO: Handle error.
356 }
357 defer c.Close()
358
359 req := &iampb.SetIamPolicyRequest{
360 // TODO: Fill request struct fields.
361 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
362 }
363 resp, err := c.SetIamPolicy(ctx, req)
364 if err != nil {
365 // TODO: Handle error.
366 }
367 // TODO: Use resp.
368 _ = resp
369 }
370
371 func ExampleTopicAdminClient_TestIamPermissions() {
372 ctx := context.Background()
373 // This snippet has been automatically generated and should be regarded as a code template only.
374 // It will require modifications to work:
375 // - It may require correct/in-range values for request initialization.
376 // - It may require specifying regional endpoints when creating the service client as shown in:
377 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
378 c, err := pubsub.NewTopicAdminClient(ctx)
379 if err != nil {
380 // TODO: Handle error.
381 }
382 defer c.Close()
383
384 req := &iampb.TestIamPermissionsRequest{
385 // TODO: Fill request struct fields.
386 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
387 }
388 resp, err := c.TestIamPermissions(ctx, req)
389 if err != nil {
390 // TODO: Handle error.
391 }
392 // TODO: Use resp.
393 _ = resp
394 }