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