cloud.google.com/go/aiplatform@v1.106.0/apiv1/persistent_resource_client_example_test.go (about) 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 aiplatform_test 18 19 import ( 20 "context" 21 22 aiplatform "cloud.google.com/go/aiplatform/apiv1" 23 aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb" 24 iampb "cloud.google.com/go/iam/apiv1/iampb" 25 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 26 "google.golang.org/api/iterator" 27 locationpb "google.golang.org/genproto/googleapis/cloud/location" 28 ) 29 30 func ExampleNewPersistentResourceClient() { 31 ctx := context.Background() 32 // This snippet has been automatically generated and should be regarded as a code template only. 33 // It will require modifications to work: 34 // - It may require correct/in-range values for request initialization. 35 // - It may require specifying regional endpoints when creating the service client as shown in: 36 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 37 c, err := aiplatform.NewPersistentResourceClient(ctx) 38 if err != nil { 39 // TODO: Handle error. 40 } 41 defer c.Close() 42 43 // TODO: Use client. 44 _ = c 45 } 46 47 func ExamplePersistentResourceClient_CreatePersistentResource() { 48 ctx := context.Background() 49 // This snippet has been automatically generated and should be regarded as a code template only. 50 // It will require modifications to work: 51 // - It may require correct/in-range values for request initialization. 52 // - It may require specifying regional endpoints when creating the service client as shown in: 53 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 54 c, err := aiplatform.NewPersistentResourceClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 req := &aiplatformpb.CreatePersistentResourceRequest{ 61 // TODO: Fill request struct fields. 62 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CreatePersistentResourceRequest. 63 } 64 op, err := c.CreatePersistentResource(ctx, req) 65 if err != nil { 66 // TODO: Handle error. 67 } 68 69 resp, err := op.Wait(ctx) 70 if err != nil { 71 // TODO: Handle error. 72 } 73 // TODO: Use resp. 74 _ = resp 75 } 76 77 func ExamplePersistentResourceClient_DeletePersistentResource() { 78 ctx := context.Background() 79 // This snippet has been automatically generated and should be regarded as a code template only. 80 // It will require modifications to work: 81 // - It may require correct/in-range values for request initialization. 82 // - It may require specifying regional endpoints when creating the service client as shown in: 83 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 84 c, err := aiplatform.NewPersistentResourceClient(ctx) 85 if err != nil { 86 // TODO: Handle error. 87 } 88 defer c.Close() 89 90 req := &aiplatformpb.DeletePersistentResourceRequest{ 91 // TODO: Fill request struct fields. 92 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#DeletePersistentResourceRequest. 93 } 94 op, err := c.DeletePersistentResource(ctx, req) 95 if err != nil { 96 // TODO: Handle error. 97 } 98 99 err = op.Wait(ctx) 100 if err != nil { 101 // TODO: Handle error. 102 } 103 } 104 105 func ExamplePersistentResourceClient_GetPersistentResource() { 106 ctx := context.Background() 107 // This snippet has been automatically generated and should be regarded as a code template only. 108 // It will require modifications to work: 109 // - It may require correct/in-range values for request initialization. 110 // - It may require specifying regional endpoints when creating the service client as shown in: 111 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 112 c, err := aiplatform.NewPersistentResourceClient(ctx) 113 if err != nil { 114 // TODO: Handle error. 115 } 116 defer c.Close() 117 118 req := &aiplatformpb.GetPersistentResourceRequest{ 119 // TODO: Fill request struct fields. 120 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#GetPersistentResourceRequest. 121 } 122 resp, err := c.GetPersistentResource(ctx, req) 123 if err != nil { 124 // TODO: Handle error. 125 } 126 // TODO: Use resp. 127 _ = resp 128 } 129 130 func ExamplePersistentResourceClient_ListPersistentResources() { 131 ctx := context.Background() 132 // This snippet has been automatically generated and should be regarded as a code template only. 133 // It will require modifications to work: 134 // - It may require correct/in-range values for request initialization. 135 // - It may require specifying regional endpoints when creating the service client as shown in: 136 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 137 c, err := aiplatform.NewPersistentResourceClient(ctx) 138 if err != nil { 139 // TODO: Handle error. 140 } 141 defer c.Close() 142 143 req := &aiplatformpb.ListPersistentResourcesRequest{ 144 // TODO: Fill request struct fields. 145 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ListPersistentResourcesRequest. 146 } 147 it := c.ListPersistentResources(ctx, req) 148 for { 149 resp, err := it.Next() 150 if err == iterator.Done { 151 break 152 } 153 if err != nil { 154 // TODO: Handle error. 155 } 156 // TODO: Use resp. 157 _ = resp 158 159 // If you need to access the underlying RPC response, 160 // you can do so by casting the `Response` as below. 161 // Otherwise, remove this line. Only populated after 162 // first call to Next(). Not safe for concurrent access. 163 _ = it.Response.(*aiplatformpb.ListPersistentResourcesResponse) 164 } 165 } 166 167 func ExamplePersistentResourceClient_RebootPersistentResource() { 168 ctx := context.Background() 169 // This snippet has been automatically generated and should be regarded as a code template only. 170 // It will require modifications to work: 171 // - It may require correct/in-range values for request initialization. 172 // - It may require specifying regional endpoints when creating the service client as shown in: 173 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 174 c, err := aiplatform.NewPersistentResourceClient(ctx) 175 if err != nil { 176 // TODO: Handle error. 177 } 178 defer c.Close() 179 180 req := &aiplatformpb.RebootPersistentResourceRequest{ 181 // TODO: Fill request struct fields. 182 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#RebootPersistentResourceRequest. 183 } 184 op, err := c.RebootPersistentResource(ctx, req) 185 if err != nil { 186 // TODO: Handle error. 187 } 188 189 resp, err := op.Wait(ctx) 190 if err != nil { 191 // TODO: Handle error. 192 } 193 // TODO: Use resp. 194 _ = resp 195 } 196 197 func ExamplePersistentResourceClient_UpdatePersistentResource() { 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 := aiplatform.NewPersistentResourceClient(ctx) 205 if err != nil { 206 // TODO: Handle error. 207 } 208 defer c.Close() 209 210 req := &aiplatformpb.UpdatePersistentResourceRequest{ 211 // TODO: Fill request struct fields. 212 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpdatePersistentResourceRequest. 213 } 214 op, err := c.UpdatePersistentResource(ctx, req) 215 if err != nil { 216 // TODO: Handle error. 217 } 218 219 resp, err := op.Wait(ctx) 220 if err != nil { 221 // TODO: Handle error. 222 } 223 // TODO: Use resp. 224 _ = resp 225 } 226 227 func ExamplePersistentResourceClient_GetLocation() { 228 ctx := context.Background() 229 // This snippet has been automatically generated and should be regarded as a code template only. 230 // It will require modifications to work: 231 // - It may require correct/in-range values for request initialization. 232 // - It may require specifying regional endpoints when creating the service client as shown in: 233 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 234 c, err := aiplatform.NewPersistentResourceClient(ctx) 235 if err != nil { 236 // TODO: Handle error. 237 } 238 defer c.Close() 239 240 req := &locationpb.GetLocationRequest{ 241 // TODO: Fill request struct fields. 242 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 243 } 244 resp, err := c.GetLocation(ctx, req) 245 if err != nil { 246 // TODO: Handle error. 247 } 248 // TODO: Use resp. 249 _ = resp 250 } 251 252 func ExamplePersistentResourceClient_ListLocations() { 253 ctx := context.Background() 254 // This snippet has been automatically generated and should be regarded as a code template only. 255 // It will require modifications to work: 256 // - It may require correct/in-range values for request initialization. 257 // - It may require specifying regional endpoints when creating the service client as shown in: 258 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 259 c, err := aiplatform.NewPersistentResourceClient(ctx) 260 if err != nil { 261 // TODO: Handle error. 262 } 263 defer c.Close() 264 265 req := &locationpb.ListLocationsRequest{ 266 // TODO: Fill request struct fields. 267 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 268 } 269 it := c.ListLocations(ctx, req) 270 for { 271 resp, err := it.Next() 272 if err == iterator.Done { 273 break 274 } 275 if err != nil { 276 // TODO: Handle error. 277 } 278 // TODO: Use resp. 279 _ = resp 280 281 // If you need to access the underlying RPC response, 282 // you can do so by casting the `Response` as below. 283 // Otherwise, remove this line. Only populated after 284 // first call to Next(). Not safe for concurrent access. 285 _ = it.Response.(*locationpb.ListLocationsResponse) 286 } 287 } 288 289 func ExamplePersistentResourceClient_GetIamPolicy() { 290 ctx := context.Background() 291 // This snippet has been automatically generated and should be regarded as a code template only. 292 // It will require modifications to work: 293 // - It may require correct/in-range values for request initialization. 294 // - It may require specifying regional endpoints when creating the service client as shown in: 295 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 296 c, err := aiplatform.NewPersistentResourceClient(ctx) 297 if err != nil { 298 // TODO: Handle error. 299 } 300 defer c.Close() 301 302 req := &iampb.GetIamPolicyRequest{ 303 // TODO: Fill request struct fields. 304 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 305 } 306 resp, err := c.GetIamPolicy(ctx, req) 307 if err != nil { 308 // TODO: Handle error. 309 } 310 // TODO: Use resp. 311 _ = resp 312 } 313 314 func ExamplePersistentResourceClient_SetIamPolicy() { 315 ctx := context.Background() 316 // This snippet has been automatically generated and should be regarded as a code template only. 317 // It will require modifications to work: 318 // - It may require correct/in-range values for request initialization. 319 // - It may require specifying regional endpoints when creating the service client as shown in: 320 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 321 c, err := aiplatform.NewPersistentResourceClient(ctx) 322 if err != nil { 323 // TODO: Handle error. 324 } 325 defer c.Close() 326 327 req := &iampb.SetIamPolicyRequest{ 328 // TODO: Fill request struct fields. 329 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 330 } 331 resp, err := c.SetIamPolicy(ctx, req) 332 if err != nil { 333 // TODO: Handle error. 334 } 335 // TODO: Use resp. 336 _ = resp 337 } 338 339 func ExamplePersistentResourceClient_TestIamPermissions() { 340 ctx := context.Background() 341 // This snippet has been automatically generated and should be regarded as a code template only. 342 // It will require modifications to work: 343 // - It may require correct/in-range values for request initialization. 344 // - It may require specifying regional endpoints when creating the service client as shown in: 345 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 346 c, err := aiplatform.NewPersistentResourceClient(ctx) 347 if err != nil { 348 // TODO: Handle error. 349 } 350 defer c.Close() 351 352 req := &iampb.TestIamPermissionsRequest{ 353 // TODO: Fill request struct fields. 354 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 355 } 356 resp, err := c.TestIamPermissions(ctx, req) 357 if err != nil { 358 // TODO: Handle error. 359 } 360 // TODO: Use resp. 361 _ = resp 362 } 363 364 func ExamplePersistentResourceClient_CancelOperation() { 365 ctx := context.Background() 366 // This snippet has been automatically generated and should be regarded as a code template only. 367 // It will require modifications to work: 368 // - It may require correct/in-range values for request initialization. 369 // - It may require specifying regional endpoints when creating the service client as shown in: 370 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 371 c, err := aiplatform.NewPersistentResourceClient(ctx) 372 if err != nil { 373 // TODO: Handle error. 374 } 375 defer c.Close() 376 377 req := &longrunningpb.CancelOperationRequest{ 378 // TODO: Fill request struct fields. 379 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 380 } 381 err = c.CancelOperation(ctx, req) 382 if err != nil { 383 // TODO: Handle error. 384 } 385 } 386 387 func ExamplePersistentResourceClient_DeleteOperation() { 388 ctx := context.Background() 389 // This snippet has been automatically generated and should be regarded as a code template only. 390 // It will require modifications to work: 391 // - It may require correct/in-range values for request initialization. 392 // - It may require specifying regional endpoints when creating the service client as shown in: 393 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 394 c, err := aiplatform.NewPersistentResourceClient(ctx) 395 if err != nil { 396 // TODO: Handle error. 397 } 398 defer c.Close() 399 400 req := &longrunningpb.DeleteOperationRequest{ 401 // TODO: Fill request struct fields. 402 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 403 } 404 err = c.DeleteOperation(ctx, req) 405 if err != nil { 406 // TODO: Handle error. 407 } 408 } 409 410 func ExamplePersistentResourceClient_GetOperation() { 411 ctx := context.Background() 412 // This snippet has been automatically generated and should be regarded as a code template only. 413 // It will require modifications to work: 414 // - It may require correct/in-range values for request initialization. 415 // - It may require specifying regional endpoints when creating the service client as shown in: 416 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 417 c, err := aiplatform.NewPersistentResourceClient(ctx) 418 if err != nil { 419 // TODO: Handle error. 420 } 421 defer c.Close() 422 423 req := &longrunningpb.GetOperationRequest{ 424 // TODO: Fill request struct fields. 425 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 426 } 427 resp, err := c.GetOperation(ctx, req) 428 if err != nil { 429 // TODO: Handle error. 430 } 431 // TODO: Use resp. 432 _ = resp 433 } 434 435 func ExamplePersistentResourceClient_ListOperations() { 436 ctx := context.Background() 437 // This snippet has been automatically generated and should be regarded as a code template only. 438 // It will require modifications to work: 439 // - It may require correct/in-range values for request initialization. 440 // - It may require specifying regional endpoints when creating the service client as shown in: 441 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 442 c, err := aiplatform.NewPersistentResourceClient(ctx) 443 if err != nil { 444 // TODO: Handle error. 445 } 446 defer c.Close() 447 448 req := &longrunningpb.ListOperationsRequest{ 449 // TODO: Fill request struct fields. 450 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 451 } 452 it := c.ListOperations(ctx, req) 453 for { 454 resp, err := it.Next() 455 if err == iterator.Done { 456 break 457 } 458 if err != nil { 459 // TODO: Handle error. 460 } 461 // TODO: Use resp. 462 _ = resp 463 464 // If you need to access the underlying RPC response, 465 // you can do so by casting the `Response` as below. 466 // Otherwise, remove this line. Only populated after 467 // first call to Next(). Not safe for concurrent access. 468 _ = it.Response.(*longrunningpb.ListOperationsResponse) 469 } 470 } 471 472 func ExamplePersistentResourceClient_WaitOperation() { 473 ctx := context.Background() 474 // This snippet has been automatically generated and should be regarded as a code template only. 475 // It will require modifications to work: 476 // - It may require correct/in-range values for request initialization. 477 // - It may require specifying regional endpoints when creating the service client as shown in: 478 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 479 c, err := aiplatform.NewPersistentResourceClient(ctx) 480 if err != nil { 481 // TODO: Handle error. 482 } 483 defer c.Close() 484 485 req := &longrunningpb.WaitOperationRequest{ 486 // TODO: Fill request struct fields. 487 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 488 } 489 resp, err := c.WaitOperation(ctx, req) 490 if err != nil { 491 // TODO: Handle error. 492 } 493 // TODO: Use resp. 494 _ = resp 495 }