Debian Codegraph @

pubsub/v2/apiv1/schema_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 ExampleNewSchemaClient() {
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.NewSchemaClient(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 ExampleNewSchemaRESTClient() {
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.NewSchemaRESTClient(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 ExampleSchemaClient_CommitSchema() {
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.NewSchemaClient(ctx)
70 if err != nil {
71 // TODO: Handle error.
72 }
73 defer c.Close()
74
75 req := &pubsubpb.CommitSchemaRequest{
76 // TODO: Fill request struct fields.
77 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#CommitSchemaRequest.
78 }
79 resp, err := c.CommitSchema(ctx, req)
80 if err != nil {
81 // TODO: Handle error.
82 }
83 // TODO: Use resp.
84 _ = resp
85 }
86
87 func ExampleSchemaClient_CreateSchema() {
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.NewSchemaClient(ctx)
95 if err != nil {
96 // TODO: Handle error.
97 }
98 defer c.Close()
99
100 req := &pubsubpb.CreateSchemaRequest{
101 // TODO: Fill request struct fields.
102 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#CreateSchemaRequest.
103 }
104 resp, err := c.CreateSchema(ctx, req)
105 if err != nil {
106 // TODO: Handle error.
107 }
108 // TODO: Use resp.
109 _ = resp
110 }
111
112 func ExampleSchemaClient_DeleteSchema() {
113 ctx := context.Background()
114 // This snippet has been automatically generated and should be regarded as a code template only.
115 // It will require modifications to work:
116 // - It may require correct/in-range values for request initialization.
117 // - It may require specifying regional endpoints when creating the service client as shown in:
118 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
119 c, err := pubsub.NewSchemaClient(ctx)
120 if err != nil {
121 // TODO: Handle error.
122 }
123 defer c.Close()
124
125 req := &pubsubpb.DeleteSchemaRequest{
126 // TODO: Fill request struct fields.
127 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteSchemaRequest.
128 }
129 err = c.DeleteSchema(ctx, req)
130 if err != nil {
131 // TODO: Handle error.
132 }
133 }
134
135 func ExampleSchemaClient_DeleteSchemaRevision() {
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.NewSchemaClient(ctx)
143 if err != nil {
144 // TODO: Handle error.
145 }
146 defer c.Close()
147
148 req := &pubsubpb.DeleteSchemaRevisionRequest{
149 // TODO: Fill request struct fields.
150 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteSchemaRevisionRequest.
151 }
152 resp, err := c.DeleteSchemaRevision(ctx, req)
153 if err != nil {
154 // TODO: Handle error.
155 }
156 // TODO: Use resp.
157 _ = resp
158 }
159
160 func ExampleSchemaClient_GetSchema() {
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.NewSchemaClient(ctx)
168 if err != nil {
169 // TODO: Handle error.
170 }
171 defer c.Close()
172
173 req := &pubsubpb.GetSchemaRequest{
174 // TODO: Fill request struct fields.
175 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#GetSchemaRequest.
176 }
177 resp, err := c.GetSchema(ctx, req)
178 if err != nil {
179 // TODO: Handle error.
180 }
181 // TODO: Use resp.
182 _ = resp
183 }
184
185 func ExampleSchemaClient_ListSchemaRevisions() {
186 ctx := context.Background()
187 // This snippet has been automatically generated and should be regarded as a code template only.
188 // It will require modifications to work:
189 // - It may require correct/in-range values for request initialization.
190 // - It may require specifying regional endpoints when creating the service client as shown in:
191 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
192 c, err := pubsub.NewSchemaClient(ctx)
193 if err != nil {
194 // TODO: Handle error.
195 }
196 defer c.Close()
197
198 req := &pubsubpb.ListSchemaRevisionsRequest{
199 // TODO: Fill request struct fields.
200 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSchemaRevisionsRequest.
201 }
202 it := c.ListSchemaRevisions(ctx, req)
203 for {
204 resp, err := it.Next()
205 if err == iterator.Done {
206 break
207 }
208 if err != nil {
209 // TODO: Handle error.
210 }
211 // TODO: Use resp.
212 _ = resp
213
214 // If you need to access the underlying RPC response,
215 // you can do so by casting the `Response` as below.
216 // Otherwise, remove this line. Only populated after
217 // first call to Next(). Not safe for concurrent access.
218 _ = it.Response.(*pubsubpb.ListSchemaRevisionsResponse)
219 }
220 }
221
222 func ExampleSchemaClient_ListSchemas() {
223 ctx := context.Background()
224 // This snippet has been automatically generated and should be regarded as a code template only.
225 // It will require modifications to work:
226 // - It may require correct/in-range values for request initialization.
227 // - It may require specifying regional endpoints when creating the service client as shown in:
228 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
229 c, err := pubsub.NewSchemaClient(ctx)
230 if err != nil {
231 // TODO: Handle error.
232 }
233 defer c.Close()
234
235 req := &pubsubpb.ListSchemasRequest{
236 // TODO: Fill request struct fields.
237 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSchemasRequest.
238 }
239 it := c.ListSchemas(ctx, req)
240 for {
241 resp, err := it.Next()
242 if err == iterator.Done {
243 break
244 }
245 if err != nil {
246 // TODO: Handle error.
247 }
248 // TODO: Use resp.
249 _ = resp
250
251 // If you need to access the underlying RPC response,
252 // you can do so by casting the `Response` as below.
253 // Otherwise, remove this line. Only populated after
254 // first call to Next(). Not safe for concurrent access.
255 _ = it.Response.(*pubsubpb.ListSchemasResponse)
256 }
257 }
258
259 func ExampleSchemaClient_RollbackSchema() {
260 ctx := context.Background()
261 // This snippet has been automatically generated and should be regarded as a code template only.
262 // It will require modifications to work:
263 // - It may require correct/in-range values for request initialization.
264 // - It may require specifying regional endpoints when creating the service client as shown in:
265 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
266 c, err := pubsub.NewSchemaClient(ctx)
267 if err != nil {
268 // TODO: Handle error.
269 }
270 defer c.Close()
271
272 req := &pubsubpb.RollbackSchemaRequest{
273 // TODO: Fill request struct fields.
274 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#RollbackSchemaRequest.
275 }
276 resp, err := c.RollbackSchema(ctx, req)
277 if err != nil {
278 // TODO: Handle error.
279 }
280 // TODO: Use resp.
281 _ = resp
282 }
283
284 func ExampleSchemaClient_ValidateMessage() {
285 ctx := context.Background()
286 // This snippet has been automatically generated and should be regarded as a code template only.
287 // It will require modifications to work:
288 // - It may require correct/in-range values for request initialization.
289 // - It may require specifying regional endpoints when creating the service client as shown in:
290 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
291 c, err := pubsub.NewSchemaClient(ctx)
292 if err != nil {
293 // TODO: Handle error.
294 }
295 defer c.Close()
296
297 req := &pubsubpb.ValidateMessageRequest{
298 // TODO: Fill request struct fields.
299 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ValidateMessageRequest.
300 }
301 resp, err := c.ValidateMessage(ctx, req)
302 if err != nil {
303 // TODO: Handle error.
304 }
305 // TODO: Use resp.
306 _ = resp
307 }
308
309 func ExampleSchemaClient_ValidateSchema() {
310 ctx := context.Background()
311 // This snippet has been automatically generated and should be regarded as a code template only.
312 // It will require modifications to work:
313 // - It may require correct/in-range values for request initialization.
314 // - It may require specifying regional endpoints when creating the service client as shown in:
315 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
316 c, err := pubsub.NewSchemaClient(ctx)
317 if err != nil {
318 // TODO: Handle error.
319 }
320 defer c.Close()
321
322 req := &pubsubpb.ValidateSchemaRequest{
323 // TODO: Fill request struct fields.
324 // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ValidateSchemaRequest.
325 }
326 resp, err := c.ValidateSchema(ctx, req)
327 if err != nil {
328 // TODO: Handle error.
329 }
330 // TODO: Use resp.
331 _ = resp
332 }
333
334 func ExampleSchemaClient_GetIamPolicy() {
335 ctx := context.Background()
336 // This snippet has been automatically generated and should be regarded as a code template only.
337 // It will require modifications to work:
338 // - It may require correct/in-range values for request initialization.
339 // - It may require specifying regional endpoints when creating the service client as shown in:
340 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
341 c, err := pubsub.NewSchemaClient(ctx)
342 if err != nil {
343 // TODO: Handle error.
344 }
345 defer c.Close()
346
347 req := &iampb.GetIamPolicyRequest{
348 // TODO: Fill request struct fields.
349 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
350 }
351 resp, err := c.GetIamPolicy(ctx, req)
352 if err != nil {
353 // TODO: Handle error.
354 }
355 // TODO: Use resp.
356 _ = resp
357 }
358
359 func ExampleSchemaClient_SetIamPolicy() {
360 ctx := context.Background()
361 // This snippet has been automatically generated and should be regarded as a code template only.
362 // It will require modifications to work:
363 // - It may require correct/in-range values for request initialization.
364 // - It may require specifying regional endpoints when creating the service client as shown in:
365 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
366 c, err := pubsub.NewSchemaClient(ctx)
367 if err != nil {
368 // TODO: Handle error.
369 }
370 defer c.Close()
371
372 req := &iampb.SetIamPolicyRequest{
373 // TODO: Fill request struct fields.
374 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
375 }
376 resp, err := c.SetIamPolicy(ctx, req)
377 if err != nil {
378 // TODO: Handle error.
379 }
380 // TODO: Use resp.
381 _ = resp
382 }
383
384 func ExampleSchemaClient_TestIamPermissions() {
385 ctx := context.Background()
386 // This snippet has been automatically generated and should be regarded as a code template only.
387 // It will require modifications to work:
388 // - It may require correct/in-range values for request initialization.
389 // - It may require specifying regional endpoints when creating the service client as shown in:
390 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
391 c, err := pubsub.NewSchemaClient(ctx)
392 if err != nil {
393 // TODO: Handle error.
394 }
395 defer c.Close()
396
397 req := &iampb.TestIamPermissionsRequest{
398 // TODO: Fill request struct fields.
399 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
400 }
401 resp, err := c.TestIamPermissions(ctx, req)
402 if err != nil {
403 // TODO: Handle error.
404 }
405 // TODO: Use resp.
406 _ = resp
407 }