cloud.google.com/go/aiplatform@v1.106.0/apiv1/gen_ai_cache_client.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 18 19 import ( 20 "context" 21 "fmt" 22 "log/slog" 23 "math" 24 "net/url" 25 26 aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb" 27 iampb "cloud.google.com/go/iam/apiv1/iampb" 28 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 29 gax "github.com/googleapis/gax-go/v2" 30 "google.golang.org/api/iterator" 31 "google.golang.org/api/option" 32 "google.golang.org/api/option/internaloption" 33 gtransport "google.golang.org/api/transport/grpc" 34 locationpb "google.golang.org/genproto/googleapis/cloud/location" 35 "google.golang.org/grpc" 36 "google.golang.org/protobuf/proto" 37 ) 38 39 var newGenAiCacheClientHook clientHook 40 41 // GenAiCacheCallOptions contains the retry settings for each method of GenAiCacheClient. 42 type GenAiCacheCallOptions struct { 43 CreateCachedContent []gax.CallOption 44 GetCachedContent []gax.CallOption 45 UpdateCachedContent []gax.CallOption 46 DeleteCachedContent []gax.CallOption 47 ListCachedContents []gax.CallOption 48 GetLocation []gax.CallOption 49 ListLocations []gax.CallOption 50 GetIamPolicy []gax.CallOption 51 SetIamPolicy []gax.CallOption 52 TestIamPermissions []gax.CallOption 53 CancelOperation []gax.CallOption 54 DeleteOperation []gax.CallOption 55 GetOperation []gax.CallOption 56 ListOperations []gax.CallOption 57 WaitOperation []gax.CallOption 58 } 59 60 func defaultGenAiCacheGRPCClientOptions() []option.ClientOption { 61 return []option.ClientOption{ 62 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 63 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 64 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 65 internaloption.WithDefaultUniverseDomain("googleapis.com"), 66 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 67 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 68 internaloption.EnableJwtWithScope(), 69 internaloption.EnableNewAuthLibrary(), 70 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 71 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 72 } 73 } 74 75 func defaultGenAiCacheCallOptions() *GenAiCacheCallOptions { 76 return &GenAiCacheCallOptions{ 77 CreateCachedContent: []gax.CallOption{}, 78 GetCachedContent: []gax.CallOption{}, 79 UpdateCachedContent: []gax.CallOption{}, 80 DeleteCachedContent: []gax.CallOption{}, 81 ListCachedContents: []gax.CallOption{}, 82 GetLocation: []gax.CallOption{}, 83 ListLocations: []gax.CallOption{}, 84 GetIamPolicy: []gax.CallOption{}, 85 SetIamPolicy: []gax.CallOption{}, 86 TestIamPermissions: []gax.CallOption{}, 87 CancelOperation: []gax.CallOption{}, 88 DeleteOperation: []gax.CallOption{}, 89 GetOperation: []gax.CallOption{}, 90 ListOperations: []gax.CallOption{}, 91 WaitOperation: []gax.CallOption{}, 92 } 93 } 94 95 // internalGenAiCacheClient is an interface that defines the methods available from Vertex AI API. 96 type internalGenAiCacheClient interface { 97 Close() error 98 setGoogleClientInfo(...string) 99 Connection() *grpc.ClientConn 100 CreateCachedContent(context.Context, *aiplatformpb.CreateCachedContentRequest, ...gax.CallOption) (*aiplatformpb.CachedContent, error) 101 GetCachedContent(context.Context, *aiplatformpb.GetCachedContentRequest, ...gax.CallOption) (*aiplatformpb.CachedContent, error) 102 UpdateCachedContent(context.Context, *aiplatformpb.UpdateCachedContentRequest, ...gax.CallOption) (*aiplatformpb.CachedContent, error) 103 DeleteCachedContent(context.Context, *aiplatformpb.DeleteCachedContentRequest, ...gax.CallOption) error 104 ListCachedContents(context.Context, *aiplatformpb.ListCachedContentsRequest, ...gax.CallOption) *CachedContentIterator 105 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 106 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 107 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 108 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 109 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 110 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 111 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 112 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 113 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 114 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 115 } 116 117 // GenAiCacheClient is a client for interacting with Vertex AI API. 118 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 119 // 120 // Service for managing Vertex AI’s CachedContent resource. 121 type GenAiCacheClient struct { 122 // The internal transport-dependent client. 123 internalClient internalGenAiCacheClient 124 125 // The call options for this service. 126 CallOptions *GenAiCacheCallOptions 127 } 128 129 // Wrapper methods routed to the internal client. 130 131 // Close closes the connection to the API service. The user should invoke this when 132 // the client is no longer required. 133 func (c *GenAiCacheClient) Close() error { 134 return c.internalClient.Close() 135 } 136 137 // setGoogleClientInfo sets the name and version of the application in 138 // the `x-goog-api-client` header passed on each request. Intended for 139 // use by Google-written clients. 140 func (c *GenAiCacheClient) setGoogleClientInfo(keyval ...string) { 141 c.internalClient.setGoogleClientInfo(keyval...) 142 } 143 144 // Connection returns a connection to the API service. 145 // 146 // Deprecated: Connections are now pooled so this method does not always 147 // return the same resource. 148 func (c *GenAiCacheClient) Connection() *grpc.ClientConn { 149 return c.internalClient.Connection() 150 } 151 152 // CreateCachedContent creates cached content, this call will initialize the cached content in the 153 // data storage, and users need to pay for the cache data storage. 154 func (c *GenAiCacheClient) CreateCachedContent(ctx context.Context, req *aiplatformpb.CreateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 155 return c.internalClient.CreateCachedContent(ctx, req, opts...) 156 } 157 158 // GetCachedContent gets cached content configurations 159 func (c *GenAiCacheClient) GetCachedContent(ctx context.Context, req *aiplatformpb.GetCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 160 return c.internalClient.GetCachedContent(ctx, req, opts...) 161 } 162 163 // UpdateCachedContent updates cached content configurations 164 func (c *GenAiCacheClient) UpdateCachedContent(ctx context.Context, req *aiplatformpb.UpdateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 165 return c.internalClient.UpdateCachedContent(ctx, req, opts...) 166 } 167 168 // DeleteCachedContent deletes cached content 169 func (c *GenAiCacheClient) DeleteCachedContent(ctx context.Context, req *aiplatformpb.DeleteCachedContentRequest, opts ...gax.CallOption) error { 170 return c.internalClient.DeleteCachedContent(ctx, req, opts...) 171 } 172 173 // ListCachedContents lists cached contents in a project 174 func (c *GenAiCacheClient) ListCachedContents(ctx context.Context, req *aiplatformpb.ListCachedContentsRequest, opts ...gax.CallOption) *CachedContentIterator { 175 return c.internalClient.ListCachedContents(ctx, req, opts...) 176 } 177 178 // GetLocation gets information about a location. 179 func (c *GenAiCacheClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 180 return c.internalClient.GetLocation(ctx, req, opts...) 181 } 182 183 // ListLocations lists information about the supported locations for this service. 184 func (c *GenAiCacheClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 185 return c.internalClient.ListLocations(ctx, req, opts...) 186 } 187 188 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 189 // if the resource exists and does not have a policy set. 190 func (c *GenAiCacheClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 191 return c.internalClient.GetIamPolicy(ctx, req, opts...) 192 } 193 194 // SetIamPolicy sets the access control policy on the specified resource. Replaces 195 // any existing policy. 196 // 197 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 198 // errors. 199 func (c *GenAiCacheClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 200 return c.internalClient.SetIamPolicy(ctx, req, opts...) 201 } 202 203 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 204 // resource does not exist, this will return an empty set of 205 // permissions, not a NOT_FOUND error. 206 // 207 // Note: This operation is designed to be used for building 208 // permission-aware UIs and command-line tools, not for authorization 209 // checking. This operation may “fail open” without warning. 210 func (c *GenAiCacheClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 211 return c.internalClient.TestIamPermissions(ctx, req, opts...) 212 } 213 214 // CancelOperation is a utility method from google.longrunning.Operations. 215 func (c *GenAiCacheClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 216 return c.internalClient.CancelOperation(ctx, req, opts...) 217 } 218 219 // DeleteOperation is a utility method from google.longrunning.Operations. 220 func (c *GenAiCacheClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 221 return c.internalClient.DeleteOperation(ctx, req, opts...) 222 } 223 224 // GetOperation is a utility method from google.longrunning.Operations. 225 func (c *GenAiCacheClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 226 return c.internalClient.GetOperation(ctx, req, opts...) 227 } 228 229 // ListOperations is a utility method from google.longrunning.Operations. 230 func (c *GenAiCacheClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 231 return c.internalClient.ListOperations(ctx, req, opts...) 232 } 233 234 // WaitOperation is a utility method from google.longrunning.Operations. 235 func (c *GenAiCacheClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 236 return c.internalClient.WaitOperation(ctx, req, opts...) 237 } 238 239 // genAiCacheGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 240 // 241 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 242 type genAiCacheGRPCClient struct { 243 // Connection pool of gRPC connections to the service. 244 connPool gtransport.ConnPool 245 246 // Points back to the CallOptions field of the containing GenAiCacheClient 247 CallOptions **GenAiCacheCallOptions 248 249 // The gRPC API client. 250 genAiCacheClient aiplatformpb.GenAiCacheServiceClient 251 252 operationsClient longrunningpb.OperationsClient 253 254 iamPolicyClient iampb.IAMPolicyClient 255 256 locationsClient locationpb.LocationsClient 257 258 // The x-goog-* metadata to be sent with each request. 259 xGoogHeaders []string 260 261 logger *slog.Logger 262 } 263 264 // NewGenAiCacheClient creates a new gen ai cache service client based on gRPC. 265 // The returned client must be Closed when it is done being used to clean up its underlying connections. 266 // 267 // Service for managing Vertex AI’s CachedContent resource. 268 func NewGenAiCacheClient(ctx context.Context, opts ...option.ClientOption) (*GenAiCacheClient, error) { 269 clientOpts := defaultGenAiCacheGRPCClientOptions() 270 if newGenAiCacheClientHook != nil { 271 hookOpts, err := newGenAiCacheClientHook(ctx, clientHookParams{}) 272 if err != nil { 273 return nil, err 274 } 275 clientOpts = append(clientOpts, hookOpts...) 276 } 277 278 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 279 if err != nil { 280 return nil, err 281 } 282 client := GenAiCacheClient{CallOptions: defaultGenAiCacheCallOptions()} 283 284 c := &genAiCacheGRPCClient{ 285 connPool: connPool, 286 genAiCacheClient: aiplatformpb.NewGenAiCacheServiceClient(connPool), 287 CallOptions: &client.CallOptions, 288 logger: internaloption.GetLogger(opts), 289 operationsClient: longrunningpb.NewOperationsClient(connPool), 290 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 291 locationsClient: locationpb.NewLocationsClient(connPool), 292 } 293 c.setGoogleClientInfo() 294 295 client.internalClient = c 296 297 return &client, nil 298 } 299 300 // Connection returns a connection to the API service. 301 // 302 // Deprecated: Connections are now pooled so this method does not always 303 // return the same resource. 304 func (c *genAiCacheGRPCClient) Connection() *grpc.ClientConn { 305 return c.connPool.Conn() 306 } 307 308 // setGoogleClientInfo sets the name and version of the application in 309 // the `x-goog-api-client` header passed on each request. Intended for 310 // use by Google-written clients. 311 func (c *genAiCacheGRPCClient) setGoogleClientInfo(keyval ...string) { 312 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 313 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 314 c.xGoogHeaders = []string{ 315 "x-goog-api-client", gax.XGoogHeader(kv...), 316 } 317 } 318 319 // Close closes the connection to the API service. The user should invoke this when 320 // the client is no longer required. 321 func (c *genAiCacheGRPCClient) Close() error { 322 return c.connPool.Close() 323 } 324 325 func (c *genAiCacheGRPCClient) CreateCachedContent(ctx context.Context, req *aiplatformpb.CreateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 326 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 327 328 hds = append(c.xGoogHeaders, hds...) 329 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 330 opts = append((*c.CallOptions).CreateCachedContent[0:len((*c.CallOptions).CreateCachedContent):len((*c.CallOptions).CreateCachedContent)], opts...) 331 var resp *aiplatformpb.CachedContent 332 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 333 var err error 334 resp, err = executeRPC(ctx, c.genAiCacheClient.CreateCachedContent, req, settings.GRPC, c.logger, "CreateCachedContent") 335 return err 336 }, opts...) 337 if err != nil { 338 return nil, err 339 } 340 return resp, nil 341 } 342 343 func (c *genAiCacheGRPCClient) GetCachedContent(ctx context.Context, req *aiplatformpb.GetCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 344 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 345 346 hds = append(c.xGoogHeaders, hds...) 347 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 348 opts = append((*c.CallOptions).GetCachedContent[0:len((*c.CallOptions).GetCachedContent):len((*c.CallOptions).GetCachedContent)], opts...) 349 var resp *aiplatformpb.CachedContent 350 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 351 var err error 352 resp, err = executeRPC(ctx, c.genAiCacheClient.GetCachedContent, req, settings.GRPC, c.logger, "GetCachedContent") 353 return err 354 }, opts...) 355 if err != nil { 356 return nil, err 357 } 358 return resp, nil 359 } 360 361 func (c *genAiCacheGRPCClient) UpdateCachedContent(ctx context.Context, req *aiplatformpb.UpdateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 362 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "cached_content.name", url.QueryEscape(req.GetCachedContent().GetName()))} 363 364 hds = append(c.xGoogHeaders, hds...) 365 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 366 opts = append((*c.CallOptions).UpdateCachedContent[0:len((*c.CallOptions).UpdateCachedContent):len((*c.CallOptions).UpdateCachedContent)], opts...) 367 var resp *aiplatformpb.CachedContent 368 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 369 var err error 370 resp, err = executeRPC(ctx, c.genAiCacheClient.UpdateCachedContent, req, settings.GRPC, c.logger, "UpdateCachedContent") 371 return err 372 }, opts...) 373 if err != nil { 374 return nil, err 375 } 376 return resp, nil 377 } 378 379 func (c *genAiCacheGRPCClient) DeleteCachedContent(ctx context.Context, req *aiplatformpb.DeleteCachedContentRequest, opts ...gax.CallOption) error { 380 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 381 382 hds = append(c.xGoogHeaders, hds...) 383 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 384 opts = append((*c.CallOptions).DeleteCachedContent[0:len((*c.CallOptions).DeleteCachedContent):len((*c.CallOptions).DeleteCachedContent)], opts...) 385 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 386 var err error 387 _, err = executeRPC(ctx, c.genAiCacheClient.DeleteCachedContent, req, settings.GRPC, c.logger, "DeleteCachedContent") 388 return err 389 }, opts...) 390 return err 391 } 392 393 func (c *genAiCacheGRPCClient) ListCachedContents(ctx context.Context, req *aiplatformpb.ListCachedContentsRequest, opts ...gax.CallOption) *CachedContentIterator { 394 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 395 396 hds = append(c.xGoogHeaders, hds...) 397 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 398 opts = append((*c.CallOptions).ListCachedContents[0:len((*c.CallOptions).ListCachedContents):len((*c.CallOptions).ListCachedContents)], opts...) 399 it := &CachedContentIterator{} 400 req = proto.Clone(req).(*aiplatformpb.ListCachedContentsRequest) 401 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.CachedContent, string, error) { 402 resp := &aiplatformpb.ListCachedContentsResponse{} 403 if pageToken != "" { 404 req.PageToken = pageToken 405 } 406 if pageSize > math.MaxInt32 { 407 req.PageSize = math.MaxInt32 408 } else if pageSize != 0 { 409 req.PageSize = int32(pageSize) 410 } 411 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 412 var err error 413 resp, err = executeRPC(ctx, c.genAiCacheClient.ListCachedContents, req, settings.GRPC, c.logger, "ListCachedContents") 414 return err 415 }, opts...) 416 if err != nil { 417 return nil, "", err 418 } 419 420 it.Response = resp 421 return resp.GetCachedContents(), resp.GetNextPageToken(), nil 422 } 423 fetch := func(pageSize int, pageToken string) (string, error) { 424 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 425 if err != nil { 426 return "", err 427 } 428 it.items = append(it.items, items...) 429 return nextPageToken, nil 430 } 431 432 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 433 it.pageInfo.MaxSize = int(req.GetPageSize()) 434 it.pageInfo.Token = req.GetPageToken() 435 436 return it 437 } 438 439 func (c *genAiCacheGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 440 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 441 442 hds = append(c.xGoogHeaders, hds...) 443 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 444 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 445 var resp *locationpb.Location 446 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 447 var err error 448 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 449 return err 450 }, opts...) 451 if err != nil { 452 return nil, err 453 } 454 return resp, nil 455 } 456 457 func (c *genAiCacheGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 458 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 459 460 hds = append(c.xGoogHeaders, hds...) 461 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 462 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 463 it := &LocationIterator{} 464 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 465 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 466 resp := &locationpb.ListLocationsResponse{} 467 if pageToken != "" { 468 req.PageToken = pageToken 469 } 470 if pageSize > math.MaxInt32 { 471 req.PageSize = math.MaxInt32 472 } else if pageSize != 0 { 473 req.PageSize = int32(pageSize) 474 } 475 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 476 var err error 477 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 478 return err 479 }, opts...) 480 if err != nil { 481 return nil, "", err 482 } 483 484 it.Response = resp 485 return resp.GetLocations(), resp.GetNextPageToken(), nil 486 } 487 fetch := func(pageSize int, pageToken string) (string, error) { 488 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 489 if err != nil { 490 return "", err 491 } 492 it.items = append(it.items, items...) 493 return nextPageToken, nil 494 } 495 496 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 497 it.pageInfo.MaxSize = int(req.GetPageSize()) 498 it.pageInfo.Token = req.GetPageToken() 499 500 return it 501 } 502 503 func (c *genAiCacheGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 504 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 505 506 hds = append(c.xGoogHeaders, hds...) 507 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 508 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 509 var resp *iampb.Policy 510 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 511 var err error 512 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 513 return err 514 }, opts...) 515 if err != nil { 516 return nil, err 517 } 518 return resp, nil 519 } 520 521 func (c *genAiCacheGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 522 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 523 524 hds = append(c.xGoogHeaders, hds...) 525 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 526 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 527 var resp *iampb.Policy 528 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 529 var err error 530 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 531 return err 532 }, opts...) 533 if err != nil { 534 return nil, err 535 } 536 return resp, nil 537 } 538 539 func (c *genAiCacheGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 540 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 541 542 hds = append(c.xGoogHeaders, hds...) 543 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 544 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 545 var resp *iampb.TestIamPermissionsResponse 546 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 547 var err error 548 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 549 return err 550 }, opts...) 551 if err != nil { 552 return nil, err 553 } 554 return resp, nil 555 } 556 557 func (c *genAiCacheGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 558 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 559 560 hds = append(c.xGoogHeaders, hds...) 561 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 562 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 563 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 564 var err error 565 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 566 return err 567 }, opts...) 568 return err 569 } 570 571 func (c *genAiCacheGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 572 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 573 574 hds = append(c.xGoogHeaders, hds...) 575 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 576 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 577 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 578 var err error 579 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 580 return err 581 }, opts...) 582 return err 583 } 584 585 func (c *genAiCacheGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 586 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 587 588 hds = append(c.xGoogHeaders, hds...) 589 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 590 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 591 var resp *longrunningpb.Operation 592 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 593 var err error 594 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 595 return err 596 }, opts...) 597 if err != nil { 598 return nil, err 599 } 600 return resp, nil 601 } 602 603 func (c *genAiCacheGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 604 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 605 606 hds = append(c.xGoogHeaders, hds...) 607 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 608 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 609 it := &OperationIterator{} 610 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 611 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 612 resp := &longrunningpb.ListOperationsResponse{} 613 if pageToken != "" { 614 req.PageToken = pageToken 615 } 616 if pageSize > math.MaxInt32 { 617 req.PageSize = math.MaxInt32 618 } else if pageSize != 0 { 619 req.PageSize = int32(pageSize) 620 } 621 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 622 var err error 623 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 624 return err 625 }, opts...) 626 if err != nil { 627 return nil, "", err 628 } 629 630 it.Response = resp 631 return resp.GetOperations(), resp.GetNextPageToken(), nil 632 } 633 fetch := func(pageSize int, pageToken string) (string, error) { 634 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 635 if err != nil { 636 return "", err 637 } 638 it.items = append(it.items, items...) 639 return nextPageToken, nil 640 } 641 642 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 643 it.pageInfo.MaxSize = int(req.GetPageSize()) 644 it.pageInfo.Token = req.GetPageToken() 645 646 return it 647 } 648 649 func (c *genAiCacheGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 650 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 651 652 hds = append(c.xGoogHeaders, hds...) 653 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 654 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 655 var resp *longrunningpb.Operation 656 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 657 var err error 658 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 659 return err 660 }, opts...) 661 if err != nil { 662 return nil, err 663 } 664 return resp, nil 665 }