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