cloud.google.com/go/aiplatform@v1.106.0/apiv1/index_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 ExampleNewIndexClient() { 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.NewIndexClient(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 ExampleIndexClient_CreateIndex() { 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.NewIndexClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 req := &aiplatformpb.CreateIndexRequest{ 61 // TODO: Fill request struct fields. 62 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CreateIndexRequest. 63 } 64 op, err := c.CreateIndex(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 ExampleIndexClient_DeleteIndex() { 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.NewIndexClient(ctx) 85 if err != nil { 86 // TODO: Handle error. 87 } 88 defer c.Close() 89 90 req := &aiplatformpb.DeleteIndexRequest{ 91 // TODO: Fill request struct fields. 92 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#DeleteIndexRequest. 93 } 94 op, err := c.DeleteIndex(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 ExampleIndexClient_GetIndex() { 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.NewIndexClient(ctx) 113 if err != nil { 114 // TODO: Handle error. 115 } 116 defer c.Close() 117 118 req := &aiplatformpb.GetIndexRequest{ 119 // TODO: Fill request struct fields. 120 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#GetIndexRequest. 121 } 122 resp, err := c.GetIndex(ctx, req) 123 if err != nil { 124 // TODO: Handle error. 125 } 126 // TODO: Use resp. 127 _ = resp 128 } 129 130 func ExampleIndexClient_ListIndexes() { 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.NewIndexClient(ctx) 138 if err != nil { 139 // TODO: Handle error. 140 } 141 defer c.Close() 142 143 req := &aiplatformpb.ListIndexesRequest{ 144 // TODO: Fill request struct fields. 145 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ListIndexesRequest. 146 } 147 it := c.ListIndexes(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.ListIndexesResponse) 164 } 165 } 166 167 func ExampleIndexClient_RemoveDatapoints() { 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.NewIndexClient(ctx) 175 if err != nil { 176 // TODO: Handle error. 177 } 178 defer c.Close() 179 180 req := &aiplatformpb.RemoveDatapointsRequest{ 181 // TODO: Fill request struct fields. 182 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#RemoveDatapointsRequest. 183 } 184 resp, err := c.RemoveDatapoints(ctx, req) 185 if err != nil { 186 // TODO: Handle error. 187 } 188 // TODO: Use resp. 189 _ = resp 190 } 191 192 func ExampleIndexClient_UpdateIndex() { 193 ctx := context.Background() 194 // This snippet has been automatically generated and should be regarded as a code template only. 195 // It will require modifications to work: 196 // - It may require correct/in-range values for request initialization. 197 // - It may require specifying regional endpoints when creating the service client as shown in: 198 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 199 c, err := aiplatform.NewIndexClient(ctx) 200 if err != nil { 201 // TODO: Handle error. 202 } 203 defer c.Close() 204 205 req := &aiplatformpb.UpdateIndexRequest{ 206 // TODO: Fill request struct fields. 207 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpdateIndexRequest. 208 } 209 op, err := c.UpdateIndex(ctx, req) 210 if err != nil { 211 // TODO: Handle error. 212 } 213 214 resp, err := op.Wait(ctx) 215 if err != nil { 216 // TODO: Handle error. 217 } 218 // TODO: Use resp. 219 _ = resp 220 } 221 222 func ExampleIndexClient_UpsertDatapoints() { 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 := aiplatform.NewIndexClient(ctx) 230 if err != nil { 231 // TODO: Handle error. 232 } 233 defer c.Close() 234 235 req := &aiplatformpb.UpsertDatapointsRequest{ 236 // TODO: Fill request struct fields. 237 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpsertDatapointsRequest. 238 } 239 resp, err := c.UpsertDatapoints(ctx, req) 240 if err != nil { 241 // TODO: Handle error. 242 } 243 // TODO: Use resp. 244 _ = resp 245 } 246 247 func ExampleIndexClient_GetLocation() { 248 ctx := context.Background() 249 // This snippet has been automatically generated and should be regarded as a code template only. 250 // It will require modifications to work: 251 // - It may require correct/in-range values for request initialization. 252 // - It may require specifying regional endpoints when creating the service client as shown in: 253 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 254 c, err := aiplatform.NewIndexClient(ctx) 255 if err != nil { 256 // TODO: Handle error. 257 } 258 defer c.Close() 259 260 req := &locationpb.GetLocationRequest{ 261 // TODO: Fill request struct fields. 262 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 263 } 264 resp, err := c.GetLocation(ctx, req) 265 if err != nil { 266 // TODO: Handle error. 267 } 268 // TODO: Use resp. 269 _ = resp 270 } 271 272 func ExampleIndexClient_ListLocations() { 273 ctx := context.Background() 274 // This snippet has been automatically generated and should be regarded as a code template only. 275 // It will require modifications to work: 276 // - It may require correct/in-range values for request initialization. 277 // - It may require specifying regional endpoints when creating the service client as shown in: 278 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 279 c, err := aiplatform.NewIndexClient(ctx) 280 if err != nil { 281 // TODO: Handle error. 282 } 283 defer c.Close() 284 285 req := &locationpb.ListLocationsRequest{ 286 // TODO: Fill request struct fields. 287 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 288 } 289 it := c.ListLocations(ctx, req) 290 for { 291 resp, err := it.Next() 292 if err == iterator.Done { 293 break 294 } 295 if err != nil { 296 // TODO: Handle error. 297 } 298 // TODO: Use resp. 299 _ = resp 300 301 // If you need to access the underlying RPC response, 302 // you can do so by casting the `Response` as below. 303 // Otherwise, remove this line. Only populated after 304 // first call to Next(). Not safe for concurrent access. 305 _ = it.Response.(*locationpb.ListLocationsResponse) 306 } 307 } 308 309 func ExampleIndexClient_GetIamPolicy() { 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 := aiplatform.NewIndexClient(ctx) 317 if err != nil { 318 // TODO: Handle error. 319 } 320 defer c.Close() 321 322 req := &iampb.GetIamPolicyRequest{ 323 // TODO: Fill request struct fields. 324 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 325 } 326 resp, err := c.GetIamPolicy(ctx, req) 327 if err != nil { 328 // TODO: Handle error. 329 } 330 // TODO: Use resp. 331 _ = resp 332 } 333 334 func ExampleIndexClient_SetIamPolicy() { 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 := aiplatform.NewIndexClient(ctx) 342 if err != nil { 343 // TODO: Handle error. 344 } 345 defer c.Close() 346 347 req := &iampb.SetIamPolicyRequest{ 348 // TODO: Fill request struct fields. 349 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 350 } 351 resp, err := c.SetIamPolicy(ctx, req) 352 if err != nil { 353 // TODO: Handle error. 354 } 355 // TODO: Use resp. 356 _ = resp 357 } 358 359 func ExampleIndexClient_TestIamPermissions() { 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 := aiplatform.NewIndexClient(ctx) 367 if err != nil { 368 // TODO: Handle error. 369 } 370 defer c.Close() 371 372 req := &iampb.TestIamPermissionsRequest{ 373 // TODO: Fill request struct fields. 374 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 375 } 376 resp, err := c.TestIamPermissions(ctx, req) 377 if err != nil { 378 // TODO: Handle error. 379 } 380 // TODO: Use resp. 381 _ = resp 382 } 383 384 func ExampleIndexClient_CancelOperation() { 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 := aiplatform.NewIndexClient(ctx) 392 if err != nil { 393 // TODO: Handle error. 394 } 395 defer c.Close() 396 397 req := &longrunningpb.CancelOperationRequest{ 398 // TODO: Fill request struct fields. 399 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 400 } 401 err = c.CancelOperation(ctx, req) 402 if err != nil { 403 // TODO: Handle error. 404 } 405 } 406 407 func ExampleIndexClient_DeleteOperation() { 408 ctx := context.Background() 409 // This snippet has been automatically generated and should be regarded as a code template only. 410 // It will require modifications to work: 411 // - It may require correct/in-range values for request initialization. 412 // - It may require specifying regional endpoints when creating the service client as shown in: 413 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 414 c, err := aiplatform.NewIndexClient(ctx) 415 if err != nil { 416 // TODO: Handle error. 417 } 418 defer c.Close() 419 420 req := &longrunningpb.DeleteOperationRequest{ 421 // TODO: Fill request struct fields. 422 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 423 } 424 err = c.DeleteOperation(ctx, req) 425 if err != nil { 426 // TODO: Handle error. 427 } 428 } 429 430 func ExampleIndexClient_GetOperation() { 431 ctx := context.Background() 432 // This snippet has been automatically generated and should be regarded as a code template only. 433 // It will require modifications to work: 434 // - It may require correct/in-range values for request initialization. 435 // - It may require specifying regional endpoints when creating the service client as shown in: 436 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 437 c, err := aiplatform.NewIndexClient(ctx) 438 if err != nil { 439 // TODO: Handle error. 440 } 441 defer c.Close() 442 443 req := &longrunningpb.GetOperationRequest{ 444 // TODO: Fill request struct fields. 445 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 446 } 447 resp, err := c.GetOperation(ctx, req) 448 if err != nil { 449 // TODO: Handle error. 450 } 451 // TODO: Use resp. 452 _ = resp 453 } 454 455 func ExampleIndexClient_ListOperations() { 456 ctx := context.Background() 457 // This snippet has been automatically generated and should be regarded as a code template only. 458 // It will require modifications to work: 459 // - It may require correct/in-range values for request initialization. 460 // - It may require specifying regional endpoints when creating the service client as shown in: 461 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 462 c, err := aiplatform.NewIndexClient(ctx) 463 if err != nil { 464 // TODO: Handle error. 465 } 466 defer c.Close() 467 468 req := &longrunningpb.ListOperationsRequest{ 469 // TODO: Fill request struct fields. 470 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 471 } 472 it := c.ListOperations(ctx, req) 473 for { 474 resp, err := it.Next() 475 if err == iterator.Done { 476 break 477 } 478 if err != nil { 479 // TODO: Handle error. 480 } 481 // TODO: Use resp. 482 _ = resp 483 484 // If you need to access the underlying RPC response, 485 // you can do so by casting the `Response` as below. 486 // Otherwise, remove this line. Only populated after 487 // first call to Next(). Not safe for concurrent access. 488 _ = it.Response.(*longrunningpb.ListOperationsResponse) 489 } 490 } 491 492 func ExampleIndexClient_WaitOperation() { 493 ctx := context.Background() 494 // This snippet has been automatically generated and should be regarded as a code template only. 495 // It will require modifications to work: 496 // - It may require correct/in-range values for request initialization. 497 // - It may require specifying regional endpoints when creating the service client as shown in: 498 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 499 c, err := aiplatform.NewIndexClient(ctx) 500 if err != nil { 501 // TODO: Handle error. 502 } 503 defer c.Close() 504 505 req := &longrunningpb.WaitOperationRequest{ 506 // TODO: Fill request struct fields. 507 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 508 } 509 resp, err := c.WaitOperation(ctx, req) 510 if err != nil { 511 // TODO: Handle error. 512 } 513 // TODO: Use resp. 514 _ = resp 515 }