cloud.google.com/go/aiplatform@v1.106.0/apiv1/endpoint_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 ExampleNewEndpointClient() { 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.NewEndpointClient(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 ExampleEndpointClient_CreateEndpoint() { 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.NewEndpointClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 req := &aiplatformpb.CreateEndpointRequest{ 61 // TODO: Fill request struct fields. 62 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CreateEndpointRequest. 63 } 64 op, err := c.CreateEndpoint(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 ExampleEndpointClient_DeleteEndpoint() { 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.NewEndpointClient(ctx) 85 if err != nil { 86 // TODO: Handle error. 87 } 88 defer c.Close() 89 90 req := &aiplatformpb.DeleteEndpointRequest{ 91 // TODO: Fill request struct fields. 92 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#DeleteEndpointRequest. 93 } 94 op, err := c.DeleteEndpoint(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 ExampleEndpointClient_DeployModel() { 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.NewEndpointClient(ctx) 113 if err != nil { 114 // TODO: Handle error. 115 } 116 defer c.Close() 117 118 req := &aiplatformpb.DeployModelRequest{ 119 // TODO: Fill request struct fields. 120 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#DeployModelRequest. 121 } 122 op, err := c.DeployModel(ctx, req) 123 if err != nil { 124 // TODO: Handle error. 125 } 126 127 resp, err := op.Wait(ctx) 128 if err != nil { 129 // TODO: Handle error. 130 } 131 // TODO: Use resp. 132 _ = resp 133 } 134 135 func ExampleEndpointClient_GetEndpoint() { 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 := aiplatform.NewEndpointClient(ctx) 143 if err != nil { 144 // TODO: Handle error. 145 } 146 defer c.Close() 147 148 req := &aiplatformpb.GetEndpointRequest{ 149 // TODO: Fill request struct fields. 150 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#GetEndpointRequest. 151 } 152 resp, err := c.GetEndpoint(ctx, req) 153 if err != nil { 154 // TODO: Handle error. 155 } 156 // TODO: Use resp. 157 _ = resp 158 } 159 160 func ExampleEndpointClient_ListEndpoints() { 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 := aiplatform.NewEndpointClient(ctx) 168 if err != nil { 169 // TODO: Handle error. 170 } 171 defer c.Close() 172 173 req := &aiplatformpb.ListEndpointsRequest{ 174 // TODO: Fill request struct fields. 175 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ListEndpointsRequest. 176 } 177 it := c.ListEndpoints(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.(*aiplatformpb.ListEndpointsResponse) 194 } 195 } 196 197 func ExampleEndpointClient_MutateDeployedModel() { 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.NewEndpointClient(ctx) 205 if err != nil { 206 // TODO: Handle error. 207 } 208 defer c.Close() 209 210 req := &aiplatformpb.MutateDeployedModelRequest{ 211 // TODO: Fill request struct fields. 212 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#MutateDeployedModelRequest. 213 } 214 op, err := c.MutateDeployedModel(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 ExampleEndpointClient_UndeployModel() { 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.NewEndpointClient(ctx) 235 if err != nil { 236 // TODO: Handle error. 237 } 238 defer c.Close() 239 240 req := &aiplatformpb.UndeployModelRequest{ 241 // TODO: Fill request struct fields. 242 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UndeployModelRequest. 243 } 244 op, err := c.UndeployModel(ctx, req) 245 if err != nil { 246 // TODO: Handle error. 247 } 248 249 resp, err := op.Wait(ctx) 250 if err != nil { 251 // TODO: Handle error. 252 } 253 // TODO: Use resp. 254 _ = resp 255 } 256 257 func ExampleEndpointClient_UpdateEndpoint() { 258 ctx := context.Background() 259 // This snippet has been automatically generated and should be regarded as a code template only. 260 // It will require modifications to work: 261 // - It may require correct/in-range values for request initialization. 262 // - It may require specifying regional endpoints when creating the service client as shown in: 263 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 264 c, err := aiplatform.NewEndpointClient(ctx) 265 if err != nil { 266 // TODO: Handle error. 267 } 268 defer c.Close() 269 270 req := &aiplatformpb.UpdateEndpointRequest{ 271 // TODO: Fill request struct fields. 272 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpdateEndpointRequest. 273 } 274 resp, err := c.UpdateEndpoint(ctx, req) 275 if err != nil { 276 // TODO: Handle error. 277 } 278 // TODO: Use resp. 279 _ = resp 280 } 281 282 func ExampleEndpointClient_UpdateEndpointLongRunning() { 283 ctx := context.Background() 284 // This snippet has been automatically generated and should be regarded as a code template only. 285 // It will require modifications to work: 286 // - It may require correct/in-range values for request initialization. 287 // - It may require specifying regional endpoints when creating the service client as shown in: 288 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 289 c, err := aiplatform.NewEndpointClient(ctx) 290 if err != nil { 291 // TODO: Handle error. 292 } 293 defer c.Close() 294 295 req := &aiplatformpb.UpdateEndpointLongRunningRequest{ 296 // TODO: Fill request struct fields. 297 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpdateEndpointLongRunningRequest. 298 } 299 op, err := c.UpdateEndpointLongRunning(ctx, req) 300 if err != nil { 301 // TODO: Handle error. 302 } 303 304 resp, err := op.Wait(ctx) 305 if err != nil { 306 // TODO: Handle error. 307 } 308 // TODO: Use resp. 309 _ = resp 310 } 311 312 func ExampleEndpointClient_GetLocation() { 313 ctx := context.Background() 314 // This snippet has been automatically generated and should be regarded as a code template only. 315 // It will require modifications to work: 316 // - It may require correct/in-range values for request initialization. 317 // - It may require specifying regional endpoints when creating the service client as shown in: 318 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 319 c, err := aiplatform.NewEndpointClient(ctx) 320 if err != nil { 321 // TODO: Handle error. 322 } 323 defer c.Close() 324 325 req := &locationpb.GetLocationRequest{ 326 // TODO: Fill request struct fields. 327 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 328 } 329 resp, err := c.GetLocation(ctx, req) 330 if err != nil { 331 // TODO: Handle error. 332 } 333 // TODO: Use resp. 334 _ = resp 335 } 336 337 func ExampleEndpointClient_ListLocations() { 338 ctx := context.Background() 339 // This snippet has been automatically generated and should be regarded as a code template only. 340 // It will require modifications to work: 341 // - It may require correct/in-range values for request initialization. 342 // - It may require specifying regional endpoints when creating the service client as shown in: 343 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 344 c, err := aiplatform.NewEndpointClient(ctx) 345 if err != nil { 346 // TODO: Handle error. 347 } 348 defer c.Close() 349 350 req := &locationpb.ListLocationsRequest{ 351 // TODO: Fill request struct fields. 352 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 353 } 354 it := c.ListLocations(ctx, req) 355 for { 356 resp, err := it.Next() 357 if err == iterator.Done { 358 break 359 } 360 if err != nil { 361 // TODO: Handle error. 362 } 363 // TODO: Use resp. 364 _ = resp 365 366 // If you need to access the underlying RPC response, 367 // you can do so by casting the `Response` as below. 368 // Otherwise, remove this line. Only populated after 369 // first call to Next(). Not safe for concurrent access. 370 _ = it.Response.(*locationpb.ListLocationsResponse) 371 } 372 } 373 374 func ExampleEndpointClient_GetIamPolicy() { 375 ctx := context.Background() 376 // This snippet has been automatically generated and should be regarded as a code template only. 377 // It will require modifications to work: 378 // - It may require correct/in-range values for request initialization. 379 // - It may require specifying regional endpoints when creating the service client as shown in: 380 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 381 c, err := aiplatform.NewEndpointClient(ctx) 382 if err != nil { 383 // TODO: Handle error. 384 } 385 defer c.Close() 386 387 req := &iampb.GetIamPolicyRequest{ 388 // TODO: Fill request struct fields. 389 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 390 } 391 resp, err := c.GetIamPolicy(ctx, req) 392 if err != nil { 393 // TODO: Handle error. 394 } 395 // TODO: Use resp. 396 _ = resp 397 } 398 399 func ExampleEndpointClient_SetIamPolicy() { 400 ctx := context.Background() 401 // This snippet has been automatically generated and should be regarded as a code template only. 402 // It will require modifications to work: 403 // - It may require correct/in-range values for request initialization. 404 // - It may require specifying regional endpoints when creating the service client as shown in: 405 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 406 c, err := aiplatform.NewEndpointClient(ctx) 407 if err != nil { 408 // TODO: Handle error. 409 } 410 defer c.Close() 411 412 req := &iampb.SetIamPolicyRequest{ 413 // TODO: Fill request struct fields. 414 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 415 } 416 resp, err := c.SetIamPolicy(ctx, req) 417 if err != nil { 418 // TODO: Handle error. 419 } 420 // TODO: Use resp. 421 _ = resp 422 } 423 424 func ExampleEndpointClient_TestIamPermissions() { 425 ctx := context.Background() 426 // This snippet has been automatically generated and should be regarded as a code template only. 427 // It will require modifications to work: 428 // - It may require correct/in-range values for request initialization. 429 // - It may require specifying regional endpoints when creating the service client as shown in: 430 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 431 c, err := aiplatform.NewEndpointClient(ctx) 432 if err != nil { 433 // TODO: Handle error. 434 } 435 defer c.Close() 436 437 req := &iampb.TestIamPermissionsRequest{ 438 // TODO: Fill request struct fields. 439 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 440 } 441 resp, err := c.TestIamPermissions(ctx, req) 442 if err != nil { 443 // TODO: Handle error. 444 } 445 // TODO: Use resp. 446 _ = resp 447 } 448 449 func ExampleEndpointClient_CancelOperation() { 450 ctx := context.Background() 451 // This snippet has been automatically generated and should be regarded as a code template only. 452 // It will require modifications to work: 453 // - It may require correct/in-range values for request initialization. 454 // - It may require specifying regional endpoints when creating the service client as shown in: 455 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 456 c, err := aiplatform.NewEndpointClient(ctx) 457 if err != nil { 458 // TODO: Handle error. 459 } 460 defer c.Close() 461 462 req := &longrunningpb.CancelOperationRequest{ 463 // TODO: Fill request struct fields. 464 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 465 } 466 err = c.CancelOperation(ctx, req) 467 if err != nil { 468 // TODO: Handle error. 469 } 470 } 471 472 func ExampleEndpointClient_DeleteOperation() { 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.NewEndpointClient(ctx) 480 if err != nil { 481 // TODO: Handle error. 482 } 483 defer c.Close() 484 485 req := &longrunningpb.DeleteOperationRequest{ 486 // TODO: Fill request struct fields. 487 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 488 } 489 err = c.DeleteOperation(ctx, req) 490 if err != nil { 491 // TODO: Handle error. 492 } 493 } 494 495 func ExampleEndpointClient_GetOperation() { 496 ctx := context.Background() 497 // This snippet has been automatically generated and should be regarded as a code template only. 498 // It will require modifications to work: 499 // - It may require correct/in-range values for request initialization. 500 // - It may require specifying regional endpoints when creating the service client as shown in: 501 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 502 c, err := aiplatform.NewEndpointClient(ctx) 503 if err != nil { 504 // TODO: Handle error. 505 } 506 defer c.Close() 507 508 req := &longrunningpb.GetOperationRequest{ 509 // TODO: Fill request struct fields. 510 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 511 } 512 resp, err := c.GetOperation(ctx, req) 513 if err != nil { 514 // TODO: Handle error. 515 } 516 // TODO: Use resp. 517 _ = resp 518 } 519 520 func ExampleEndpointClient_ListOperations() { 521 ctx := context.Background() 522 // This snippet has been automatically generated and should be regarded as a code template only. 523 // It will require modifications to work: 524 // - It may require correct/in-range values for request initialization. 525 // - It may require specifying regional endpoints when creating the service client as shown in: 526 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 527 c, err := aiplatform.NewEndpointClient(ctx) 528 if err != nil { 529 // TODO: Handle error. 530 } 531 defer c.Close() 532 533 req := &longrunningpb.ListOperationsRequest{ 534 // TODO: Fill request struct fields. 535 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 536 } 537 it := c.ListOperations(ctx, req) 538 for { 539 resp, err := it.Next() 540 if err == iterator.Done { 541 break 542 } 543 if err != nil { 544 // TODO: Handle error. 545 } 546 // TODO: Use resp. 547 _ = resp 548 549 // If you need to access the underlying RPC response, 550 // you can do so by casting the `Response` as below. 551 // Otherwise, remove this line. Only populated after 552 // first call to Next(). Not safe for concurrent access. 553 _ = it.Response.(*longrunningpb.ListOperationsResponse) 554 } 555 } 556 557 func ExampleEndpointClient_WaitOperation() { 558 ctx := context.Background() 559 // This snippet has been automatically generated and should be regarded as a code template only. 560 // It will require modifications to work: 561 // - It may require correct/in-range values for request initialization. 562 // - It may require specifying regional endpoints when creating the service client as shown in: 563 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 564 c, err := aiplatform.NewEndpointClient(ctx) 565 if err != nil { 566 // TODO: Handle error. 567 } 568 defer c.Close() 569 570 req := &longrunningpb.WaitOperationRequest{ 571 // TODO: Fill request struct fields. 572 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 573 } 574 resp, err := c.WaitOperation(ctx, req) 575 if err != nil { 576 // TODO: Handle error. 577 } 578 // TODO: Use resp. 579 _ = resp 580 }