Debian Codegraph @

storageinsights/apiv1/storage_insights_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 storageinsights_test
18
19 import (
20 "context"
21
22 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
23 storageinsights "cloud.google.com/go/storageinsights/apiv1"
24 storageinsightspb "cloud.google.com/go/storageinsights/apiv1/storageinsightspb"
25 "google.golang.org/api/iterator"
26 locationpb "google.golang.org/genproto/googleapis/cloud/location"
27 )
28
29 func ExampleNewClient() {
30 ctx := context.Background()
31 // This snippet has been automatically generated and should be regarded as a code template only.
32 // It will require modifications to work:
33 // - It may require correct/in-range values for request initialization.
34 // - It may require specifying regional endpoints when creating the service client as shown in:
35 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
36 c, err := storageinsights.NewClient(ctx)
37 if err != nil {
38 // TODO: Handle error.
39 }
40 defer c.Close()
41
42 // TODO: Use client.
43 _ = c
44 }
45
46 func ExampleNewRESTClient() {
47 ctx := context.Background()
48 // This snippet has been automatically generated and should be regarded as a code template only.
49 // It will require modifications to work:
50 // - It may require correct/in-range values for request initialization.
51 // - It may require specifying regional endpoints when creating the service client as shown in:
52 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
53 c, err := storageinsights.NewRESTClient(ctx)
54 if err != nil {
55 // TODO: Handle error.
56 }
57 defer c.Close()
58
59 // TODO: Use client.
60 _ = c
61 }
62
63 func ExampleClient_CreateDatasetConfig() {
64 ctx := context.Background()
65 // This snippet has been automatically generated and should be regarded as a code template only.
66 // It will require modifications to work:
67 // - It may require correct/in-range values for request initialization.
68 // - It may require specifying regional endpoints when creating the service client as shown in:
69 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
70 c, err := storageinsights.NewClient(ctx)
71 if err != nil {
72 // TODO: Handle error.
73 }
74 defer c.Close()
75
76 req := &storageinsightspb.CreateDatasetConfigRequest{
77 // TODO: Fill request struct fields.
78 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#CreateDatasetConfigRequest.
79 }
80 op, err := c.CreateDatasetConfig(ctx, req)
81 if err != nil {
82 // TODO: Handle error.
83 }
84
85 resp, err := op.Wait(ctx)
86 if err != nil {
87 // TODO: Handle error.
88 }
89 // TODO: Use resp.
90 _ = resp
91 }
92
93 func ExampleClient_CreateReportConfig() {
94 ctx := context.Background()
95 // This snippet has been automatically generated and should be regarded as a code template only.
96 // It will require modifications to work:
97 // - It may require correct/in-range values for request initialization.
98 // - It may require specifying regional endpoints when creating the service client as shown in:
99 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
100 c, err := storageinsights.NewClient(ctx)
101 if err != nil {
102 // TODO: Handle error.
103 }
104 defer c.Close()
105
106 req := &storageinsightspb.CreateReportConfigRequest{
107 // TODO: Fill request struct fields.
108 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#CreateReportConfigRequest.
109 }
110 resp, err := c.CreateReportConfig(ctx, req)
111 if err != nil {
112 // TODO: Handle error.
113 }
114 // TODO: Use resp.
115 _ = resp
116 }
117
118 func ExampleClient_DeleteDatasetConfig() {
119 ctx := context.Background()
120 // This snippet has been automatically generated and should be regarded as a code template only.
121 // It will require modifications to work:
122 // - It may require correct/in-range values for request initialization.
123 // - It may require specifying regional endpoints when creating the service client as shown in:
124 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
125 c, err := storageinsights.NewClient(ctx)
126 if err != nil {
127 // TODO: Handle error.
128 }
129 defer c.Close()
130
131 req := &storageinsightspb.DeleteDatasetConfigRequest{
132 // TODO: Fill request struct fields.
133 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#DeleteDatasetConfigRequest.
134 }
135 op, err := c.DeleteDatasetConfig(ctx, req)
136 if err != nil {
137 // TODO: Handle error.
138 }
139
140 err = op.Wait(ctx)
141 if err != nil {
142 // TODO: Handle error.
143 }
144 }
145
146 func ExampleClient_DeleteReportConfig() {
147 ctx := context.Background()
148 // This snippet has been automatically generated and should be regarded as a code template only.
149 // It will require modifications to work:
150 // - It may require correct/in-range values for request initialization.
151 // - It may require specifying regional endpoints when creating the service client as shown in:
152 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
153 c, err := storageinsights.NewClient(ctx)
154 if err != nil {
155 // TODO: Handle error.
156 }
157 defer c.Close()
158
159 req := &storageinsightspb.DeleteReportConfigRequest{
160 // TODO: Fill request struct fields.
161 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#DeleteReportConfigRequest.
162 }
163 err = c.DeleteReportConfig(ctx, req)
164 if err != nil {
165 // TODO: Handle error.
166 }
167 }
168
169 func ExampleClient_GetDatasetConfig() {
170 ctx := context.Background()
171 // This snippet has been automatically generated and should be regarded as a code template only.
172 // It will require modifications to work:
173 // - It may require correct/in-range values for request initialization.
174 // - It may require specifying regional endpoints when creating the service client as shown in:
175 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
176 c, err := storageinsights.NewClient(ctx)
177 if err != nil {
178 // TODO: Handle error.
179 }
180 defer c.Close()
181
182 req := &storageinsightspb.GetDatasetConfigRequest{
183 // TODO: Fill request struct fields.
184 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#GetDatasetConfigRequest.
185 }
186 resp, err := c.GetDatasetConfig(ctx, req)
187 if err != nil {
188 // TODO: Handle error.
189 }
190 // TODO: Use resp.
191 _ = resp
192 }
193
194 func ExampleClient_GetReportConfig() {
195 ctx := context.Background()
196 // This snippet has been automatically generated and should be regarded as a code template only.
197 // It will require modifications to work:
198 // - It may require correct/in-range values for request initialization.
199 // - It may require specifying regional endpoints when creating the service client as shown in:
200 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
201 c, err := storageinsights.NewClient(ctx)
202 if err != nil {
203 // TODO: Handle error.
204 }
205 defer c.Close()
206
207 req := &storageinsightspb.GetReportConfigRequest{
208 // TODO: Fill request struct fields.
209 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#GetReportConfigRequest.
210 }
211 resp, err := c.GetReportConfig(ctx, req)
212 if err != nil {
213 // TODO: Handle error.
214 }
215 // TODO: Use resp.
216 _ = resp
217 }
218
219 func ExampleClient_GetReportDetail() {
220 ctx := context.Background()
221 // This snippet has been automatically generated and should be regarded as a code template only.
222 // It will require modifications to work:
223 // - It may require correct/in-range values for request initialization.
224 // - It may require specifying regional endpoints when creating the service client as shown in:
225 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
226 c, err := storageinsights.NewClient(ctx)
227 if err != nil {
228 // TODO: Handle error.
229 }
230 defer c.Close()
231
232 req := &storageinsightspb.GetReportDetailRequest{
233 // TODO: Fill request struct fields.
234 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#GetReportDetailRequest.
235 }
236 resp, err := c.GetReportDetail(ctx, req)
237 if err != nil {
238 // TODO: Handle error.
239 }
240 // TODO: Use resp.
241 _ = resp
242 }
243
244 func ExampleClient_LinkDataset() {
245 ctx := context.Background()
246 // This snippet has been automatically generated and should be regarded as a code template only.
247 // It will require modifications to work:
248 // - It may require correct/in-range values for request initialization.
249 // - It may require specifying regional endpoints when creating the service client as shown in:
250 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
251 c, err := storageinsights.NewClient(ctx)
252 if err != nil {
253 // TODO: Handle error.
254 }
255 defer c.Close()
256
257 req := &storageinsightspb.LinkDatasetRequest{
258 // TODO: Fill request struct fields.
259 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#LinkDatasetRequest.
260 }
261 op, err := c.LinkDataset(ctx, req)
262 if err != nil {
263 // TODO: Handle error.
264 }
265
266 resp, err := op.Wait(ctx)
267 if err != nil {
268 // TODO: Handle error.
269 }
270 // TODO: Use resp.
271 _ = resp
272 }
273
274 func ExampleClient_ListDatasetConfigs() {
275 ctx := context.Background()
276 // This snippet has been automatically generated and should be regarded as a code template only.
277 // It will require modifications to work:
278 // - It may require correct/in-range values for request initialization.
279 // - It may require specifying regional endpoints when creating the service client as shown in:
280 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
281 c, err := storageinsights.NewClient(ctx)
282 if err != nil {
283 // TODO: Handle error.
284 }
285 defer c.Close()
286
287 req := &storageinsightspb.ListDatasetConfigsRequest{
288 // TODO: Fill request struct fields.
289 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#ListDatasetConfigsRequest.
290 }
291 it := c.ListDatasetConfigs(ctx, req)
292 for {
293 resp, err := it.Next()
294 if err == iterator.Done {
295 break
296 }
297 if err != nil {
298 // TODO: Handle error.
299 }
300 // TODO: Use resp.
301 _ = resp
302
303 // If you need to access the underlying RPC response,
304 // you can do so by casting the `Response` as below.
305 // Otherwise, remove this line. Only populated after
306 // first call to Next(). Not safe for concurrent access.
307 _ = it.Response.(*storageinsightspb.ListDatasetConfigsResponse)
308 }
309 }
310
311 func ExampleClient_ListReportConfigs() {
312 ctx := context.Background()
313 // This snippet has been automatically generated and should be regarded as a code template only.
314 // It will require modifications to work:
315 // - It may require correct/in-range values for request initialization.
316 // - It may require specifying regional endpoints when creating the service client as shown in:
317 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
318 c, err := storageinsights.NewClient(ctx)
319 if err != nil {
320 // TODO: Handle error.
321 }
322 defer c.Close()
323
324 req := &storageinsightspb.ListReportConfigsRequest{
325 // TODO: Fill request struct fields.
326 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#ListReportConfigsRequest.
327 }
328 it := c.ListReportConfigs(ctx, req)
329 for {
330 resp, err := it.Next()
331 if err == iterator.Done {
332 break
333 }
334 if err != nil {
335 // TODO: Handle error.
336 }
337 // TODO: Use resp.
338 _ = resp
339
340 // If you need to access the underlying RPC response,
341 // you can do so by casting the `Response` as below.
342 // Otherwise, remove this line. Only populated after
343 // first call to Next(). Not safe for concurrent access.
344 _ = it.Response.(*storageinsightspb.ListReportConfigsResponse)
345 }
346 }
347
348 func ExampleClient_ListReportDetails() {
349 ctx := context.Background()
350 // This snippet has been automatically generated and should be regarded as a code template only.
351 // It will require modifications to work:
352 // - It may require correct/in-range values for request initialization.
353 // - It may require specifying regional endpoints when creating the service client as shown in:
354 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
355 c, err := storageinsights.NewClient(ctx)
356 if err != nil {
357 // TODO: Handle error.
358 }
359 defer c.Close()
360
361 req := &storageinsightspb.ListReportDetailsRequest{
362 // TODO: Fill request struct fields.
363 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#ListReportDetailsRequest.
364 }
365 it := c.ListReportDetails(ctx, req)
366 for {
367 resp, err := it.Next()
368 if err == iterator.Done {
369 break
370 }
371 if err != nil {
372 // TODO: Handle error.
373 }
374 // TODO: Use resp.
375 _ = resp
376
377 // If you need to access the underlying RPC response,
378 // you can do so by casting the `Response` as below.
379 // Otherwise, remove this line. Only populated after
380 // first call to Next(). Not safe for concurrent access.
381 _ = it.Response.(*storageinsightspb.ListReportDetailsResponse)
382 }
383 }
384
385 func ExampleClient_UnlinkDataset() {
386 ctx := context.Background()
387 // This snippet has been automatically generated and should be regarded as a code template only.
388 // It will require modifications to work:
389 // - It may require correct/in-range values for request initialization.
390 // - It may require specifying regional endpoints when creating the service client as shown in:
391 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
392 c, err := storageinsights.NewClient(ctx)
393 if err != nil {
394 // TODO: Handle error.
395 }
396 defer c.Close()
397
398 req := &storageinsightspb.UnlinkDatasetRequest{
399 // TODO: Fill request struct fields.
400 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#UnlinkDatasetRequest.
401 }
402 op, err := c.UnlinkDataset(ctx, req)
403 if err != nil {
404 // TODO: Handle error.
405 }
406
407 err = op.Wait(ctx)
408 if err != nil {
409 // TODO: Handle error.
410 }
411 }
412
413 func ExampleClient_UpdateDatasetConfig() {
414 ctx := context.Background()
415 // This snippet has been automatically generated and should be regarded as a code template only.
416 // It will require modifications to work:
417 // - It may require correct/in-range values for request initialization.
418 // - It may require specifying regional endpoints when creating the service client as shown in:
419 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
420 c, err := storageinsights.NewClient(ctx)
421 if err != nil {
422 // TODO: Handle error.
423 }
424 defer c.Close()
425
426 req := &storageinsightspb.UpdateDatasetConfigRequest{
427 // TODO: Fill request struct fields.
428 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#UpdateDatasetConfigRequest.
429 }
430 op, err := c.UpdateDatasetConfig(ctx, req)
431 if err != nil {
432 // TODO: Handle error.
433 }
434
435 resp, err := op.Wait(ctx)
436 if err != nil {
437 // TODO: Handle error.
438 }
439 // TODO: Use resp.
440 _ = resp
441 }
442
443 func ExampleClient_UpdateReportConfig() {
444 ctx := context.Background()
445 // This snippet has been automatically generated and should be regarded as a code template only.
446 // It will require modifications to work:
447 // - It may require correct/in-range values for request initialization.
448 // - It may require specifying regional endpoints when creating the service client as shown in:
449 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
450 c, err := storageinsights.NewClient(ctx)
451 if err != nil {
452 // TODO: Handle error.
453 }
454 defer c.Close()
455
456 req := &storageinsightspb.UpdateReportConfigRequest{
457 // TODO: Fill request struct fields.
458 // See https://pkg.go.dev/cloud.google.com/go/storageinsights/apiv1/storageinsightspb#UpdateReportConfigRequest.
459 }
460 resp, err := c.UpdateReportConfig(ctx, req)
461 if err != nil {
462 // TODO: Handle error.
463 }
464 // TODO: Use resp.
465 _ = resp
466 }
467
468 func ExampleClient_GetLocation() {
469 ctx := context.Background()
470 // This snippet has been automatically generated and should be regarded as a code template only.
471 // It will require modifications to work:
472 // - It may require correct/in-range values for request initialization.
473 // - It may require specifying regional endpoints when creating the service client as shown in:
474 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
475 c, err := storageinsights.NewClient(ctx)
476 if err != nil {
477 // TODO: Handle error.
478 }
479 defer c.Close()
480
481 req := &locationpb.GetLocationRequest{
482 // TODO: Fill request struct fields.
483 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
484 }
485 resp, err := c.GetLocation(ctx, req)
486 if err != nil {
487 // TODO: Handle error.
488 }
489 // TODO: Use resp.
490 _ = resp
491 }
492
493 func ExampleClient_ListLocations() {
494 ctx := context.Background()
495 // This snippet has been automatically generated and should be regarded as a code template only.
496 // It will require modifications to work:
497 // - It may require correct/in-range values for request initialization.
498 // - It may require specifying regional endpoints when creating the service client as shown in:
499 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
500 c, err := storageinsights.NewClient(ctx)
501 if err != nil {
502 // TODO: Handle error.
503 }
504 defer c.Close()
505
506 req := &locationpb.ListLocationsRequest{
507 // TODO: Fill request struct fields.
508 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
509 }
510 it := c.ListLocations(ctx, req)
511 for {
512 resp, err := it.Next()
513 if err == iterator.Done {
514 break
515 }
516 if err != nil {
517 // TODO: Handle error.
518 }
519 // TODO: Use resp.
520 _ = resp
521
522 // If you need to access the underlying RPC response,
523 // you can do so by casting the `Response` as below.
524 // Otherwise, remove this line. Only populated after
525 // first call to Next(). Not safe for concurrent access.
526 _ = it.Response.(*locationpb.ListLocationsResponse)
527 }
528 }
529
530 func ExampleClient_CancelOperation() {
531 ctx := context.Background()
532 // This snippet has been automatically generated and should be regarded as a code template only.
533 // It will require modifications to work:
534 // - It may require correct/in-range values for request initialization.
535 // - It may require specifying regional endpoints when creating the service client as shown in:
536 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
537 c, err := storageinsights.NewClient(ctx)
538 if err != nil {
539 // TODO: Handle error.
540 }
541 defer c.Close()
542
543 req := &longrunningpb.CancelOperationRequest{
544 // TODO: Fill request struct fields.
545 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
546 }
547 err = c.CancelOperation(ctx, req)
548 if err != nil {
549 // TODO: Handle error.
550 }
551 }
552
553 func ExampleClient_DeleteOperation() {
554 ctx := context.Background()
555 // This snippet has been automatically generated and should be regarded as a code template only.
556 // It will require modifications to work:
557 // - It may require correct/in-range values for request initialization.
558 // - It may require specifying regional endpoints when creating the service client as shown in:
559 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
560 c, err := storageinsights.NewClient(ctx)
561 if err != nil {
562 // TODO: Handle error.
563 }
564 defer c.Close()
565
566 req := &longrunningpb.DeleteOperationRequest{
567 // TODO: Fill request struct fields.
568 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
569 }
570 err = c.DeleteOperation(ctx, req)
571 if err != nil {
572 // TODO: Handle error.
573 }
574 }
575
576 func ExampleClient_GetOperation() {
577 ctx := context.Background()
578 // This snippet has been automatically generated and should be regarded as a code template only.
579 // It will require modifications to work:
580 // - It may require correct/in-range values for request initialization.
581 // - It may require specifying regional endpoints when creating the service client as shown in:
582 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
583 c, err := storageinsights.NewClient(ctx)
584 if err != nil {
585 // TODO: Handle error.
586 }
587 defer c.Close()
588
589 req := &longrunningpb.GetOperationRequest{
590 // TODO: Fill request struct fields.
591 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
592 }
593 resp, err := c.GetOperation(ctx, req)
594 if err != nil {
595 // TODO: Handle error.
596 }
597 // TODO: Use resp.
598 _ = resp
599 }
600
601 func ExampleClient_ListOperations() {
602 ctx := context.Background()
603 // This snippet has been automatically generated and should be regarded as a code template only.
604 // It will require modifications to work:
605 // - It may require correct/in-range values for request initialization.
606 // - It may require specifying regional endpoints when creating the service client as shown in:
607 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
608 c, err := storageinsights.NewClient(ctx)
609 if err != nil {
610 // TODO: Handle error.
611 }
612 defer c.Close()
613
614 req := &longrunningpb.ListOperationsRequest{
615 // TODO: Fill request struct fields.
616 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
617 }
618 it := c.ListOperations(ctx, req)
619 for {
620 resp, err := it.Next()
621 if err == iterator.Done {
622 break
623 }
624 if err != nil {
625 // TODO: Handle error.
626 }
627 // TODO: Use resp.
628 _ = resp
629
630 // If you need to access the underlying RPC response,
631 // you can do so by casting the `Response` as below.
632 // Otherwise, remove this line. Only populated after
633 // first call to Next(). Not safe for concurrent access.
634 _ = it.Response.(*longrunningpb.ListOperationsResponse)
635 }
636 }