cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/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 "bytes" 21 "context" 22 "fmt" 23 "log/slog" 24 "math" 25 "net/http" 26 "net/url" 27 28 aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" 29 iampb "cloud.google.com/go/iam/apiv1/iampb" 30 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 31 gax "github.com/googleapis/gax-go/v2" 32 "google.golang.org/api/iterator" 33 "google.golang.org/api/option" 34 "google.golang.org/api/option/internaloption" 35 gtransport "google.golang.org/api/transport/grpc" 36 httptransport "google.golang.org/api/transport/http" 37 locationpb "google.golang.org/genproto/googleapis/cloud/location" 38 "google.golang.org/grpc" 39 "google.golang.org/protobuf/encoding/protojson" 40 "google.golang.org/protobuf/proto" 41 ) 42 43 var newGenAiCacheClientHook clientHook 44 45 // GenAiCacheCallOptions contains the retry settings for each method of GenAiCacheClient. 46 type GenAiCacheCallOptions struct { 47 CreateCachedContent []gax.CallOption 48 GetCachedContent []gax.CallOption 49 UpdateCachedContent []gax.CallOption 50 DeleteCachedContent []gax.CallOption 51 ListCachedContents []gax.CallOption 52 GetLocation []gax.CallOption 53 ListLocations []gax.CallOption 54 GetIamPolicy []gax.CallOption 55 SetIamPolicy []gax.CallOption 56 TestIamPermissions []gax.CallOption 57 CancelOperation []gax.CallOption 58 DeleteOperation []gax.CallOption 59 GetOperation []gax.CallOption 60 ListOperations []gax.CallOption 61 WaitOperation []gax.CallOption 62 } 63 64 func defaultGenAiCacheGRPCClientOptions() []option.ClientOption { 65 return []option.ClientOption{ 66 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 67 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 68 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 69 internaloption.WithDefaultUniverseDomain("googleapis.com"), 70 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 71 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 72 internaloption.EnableJwtWithScope(), 73 internaloption.EnableNewAuthLibrary(), 74 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 75 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 76 } 77 } 78 79 func defaultGenAiCacheCallOptions() *GenAiCacheCallOptions { 80 return &GenAiCacheCallOptions{ 81 CreateCachedContent: []gax.CallOption{}, 82 GetCachedContent: []gax.CallOption{}, 83 UpdateCachedContent: []gax.CallOption{}, 84 DeleteCachedContent: []gax.CallOption{}, 85 ListCachedContents: []gax.CallOption{}, 86 GetLocation: []gax.CallOption{}, 87 ListLocations: []gax.CallOption{}, 88 GetIamPolicy: []gax.CallOption{}, 89 SetIamPolicy: []gax.CallOption{}, 90 TestIamPermissions: []gax.CallOption{}, 91 CancelOperation: []gax.CallOption{}, 92 DeleteOperation: []gax.CallOption{}, 93 GetOperation: []gax.CallOption{}, 94 ListOperations: []gax.CallOption{}, 95 WaitOperation: []gax.CallOption{}, 96 } 97 } 98 99 func defaultGenAiCacheRESTCallOptions() *GenAiCacheCallOptions { 100 return &GenAiCacheCallOptions{ 101 CreateCachedContent: []gax.CallOption{}, 102 GetCachedContent: []gax.CallOption{}, 103 UpdateCachedContent: []gax.CallOption{}, 104 DeleteCachedContent: []gax.CallOption{}, 105 ListCachedContents: []gax.CallOption{}, 106 GetLocation: []gax.CallOption{}, 107 ListLocations: []gax.CallOption{}, 108 GetIamPolicy: []gax.CallOption{}, 109 SetIamPolicy: []gax.CallOption{}, 110 TestIamPermissions: []gax.CallOption{}, 111 CancelOperation: []gax.CallOption{}, 112 DeleteOperation: []gax.CallOption{}, 113 GetOperation: []gax.CallOption{}, 114 ListOperations: []gax.CallOption{}, 115 WaitOperation: []gax.CallOption{}, 116 } 117 } 118 119 // internalGenAiCacheClient is an interface that defines the methods available from Vertex AI API. 120 type internalGenAiCacheClient interface { 121 Close() error 122 setGoogleClientInfo(...string) 123 Connection() *grpc.ClientConn 124 CreateCachedContent(context.Context, *aiplatformpb.CreateCachedContentRequest, ...gax.CallOption) (*aiplatformpb.CachedContent, error) 125 GetCachedContent(context.Context, *aiplatformpb.GetCachedContentRequest, ...gax.CallOption) (*aiplatformpb.CachedContent, error) 126 UpdateCachedContent(context.Context, *aiplatformpb.UpdateCachedContentRequest, ...gax.CallOption) (*aiplatformpb.CachedContent, error) 127 DeleteCachedContent(context.Context, *aiplatformpb.DeleteCachedContentRequest, ...gax.CallOption) error 128 ListCachedContents(context.Context, *aiplatformpb.ListCachedContentsRequest, ...gax.CallOption) *CachedContentIterator 129 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 130 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 131 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 132 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 133 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 134 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 135 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 136 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 137 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 138 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 139 } 140 141 // GenAiCacheClient is a client for interacting with Vertex AI API. 142 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 143 // 144 // Service for managing Vertex AI’s CachedContent resource. 145 type GenAiCacheClient struct { 146 // The internal transport-dependent client. 147 internalClient internalGenAiCacheClient 148 149 // The call options for this service. 150 CallOptions *GenAiCacheCallOptions 151 } 152 153 // Wrapper methods routed to the internal client. 154 155 // Close closes the connection to the API service. The user should invoke this when 156 // the client is no longer required. 157 func (c *GenAiCacheClient) Close() error { 158 return c.internalClient.Close() 159 } 160 161 // setGoogleClientInfo sets the name and version of the application in 162 // the `x-goog-api-client` header passed on each request. Intended for 163 // use by Google-written clients. 164 func (c *GenAiCacheClient) setGoogleClientInfo(keyval ...string) { 165 c.internalClient.setGoogleClientInfo(keyval...) 166 } 167 168 // Connection returns a connection to the API service. 169 // 170 // Deprecated: Connections are now pooled so this method does not always 171 // return the same resource. 172 func (c *GenAiCacheClient) Connection() *grpc.ClientConn { 173 return c.internalClient.Connection() 174 } 175 176 // CreateCachedContent creates cached content, this call will initialize the cached content in the 177 // data storage, and users need to pay for the cache data storage. 178 func (c *GenAiCacheClient) CreateCachedContent(ctx context.Context, req *aiplatformpb.CreateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 179 return c.internalClient.CreateCachedContent(ctx, req, opts...) 180 } 181 182 // GetCachedContent gets cached content configurations 183 func (c *GenAiCacheClient) GetCachedContent(ctx context.Context, req *aiplatformpb.GetCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 184 return c.internalClient.GetCachedContent(ctx, req, opts...) 185 } 186 187 // UpdateCachedContent updates cached content configurations 188 func (c *GenAiCacheClient) UpdateCachedContent(ctx context.Context, req *aiplatformpb.UpdateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 189 return c.internalClient.UpdateCachedContent(ctx, req, opts...) 190 } 191 192 // DeleteCachedContent deletes cached content 193 func (c *GenAiCacheClient) DeleteCachedContent(ctx context.Context, req *aiplatformpb.DeleteCachedContentRequest, opts ...gax.CallOption) error { 194 return c.internalClient.DeleteCachedContent(ctx, req, opts...) 195 } 196 197 // ListCachedContents lists cached contents in a project 198 func (c *GenAiCacheClient) ListCachedContents(ctx context.Context, req *aiplatformpb.ListCachedContentsRequest, opts ...gax.CallOption) *CachedContentIterator { 199 return c.internalClient.ListCachedContents(ctx, req, opts...) 200 } 201 202 // GetLocation gets information about a location. 203 func (c *GenAiCacheClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 204 return c.internalClient.GetLocation(ctx, req, opts...) 205 } 206 207 // ListLocations lists information about the supported locations for this service. 208 func (c *GenAiCacheClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 209 return c.internalClient.ListLocations(ctx, req, opts...) 210 } 211 212 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 213 // if the resource exists and does not have a policy set. 214 func (c *GenAiCacheClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 215 return c.internalClient.GetIamPolicy(ctx, req, opts...) 216 } 217 218 // SetIamPolicy sets the access control policy on the specified resource. Replaces 219 // any existing policy. 220 // 221 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 222 // errors. 223 func (c *GenAiCacheClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 224 return c.internalClient.SetIamPolicy(ctx, req, opts...) 225 } 226 227 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 228 // resource does not exist, this will return an empty set of 229 // permissions, not a NOT_FOUND error. 230 // 231 // Note: This operation is designed to be used for building 232 // permission-aware UIs and command-line tools, not for authorization 233 // checking. This operation may “fail open” without warning. 234 func (c *GenAiCacheClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 235 return c.internalClient.TestIamPermissions(ctx, req, opts...) 236 } 237 238 // CancelOperation is a utility method from google.longrunning.Operations. 239 func (c *GenAiCacheClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 240 return c.internalClient.CancelOperation(ctx, req, opts...) 241 } 242 243 // DeleteOperation is a utility method from google.longrunning.Operations. 244 func (c *GenAiCacheClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 245 return c.internalClient.DeleteOperation(ctx, req, opts...) 246 } 247 248 // GetOperation is a utility method from google.longrunning.Operations. 249 func (c *GenAiCacheClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 250 return c.internalClient.GetOperation(ctx, req, opts...) 251 } 252 253 // ListOperations is a utility method from google.longrunning.Operations. 254 func (c *GenAiCacheClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 255 return c.internalClient.ListOperations(ctx, req, opts...) 256 } 257 258 // WaitOperation is a utility method from google.longrunning.Operations. 259 func (c *GenAiCacheClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 260 return c.internalClient.WaitOperation(ctx, req, opts...) 261 } 262 263 // genAiCacheGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 264 // 265 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 266 type genAiCacheGRPCClient struct { 267 // Connection pool of gRPC connections to the service. 268 connPool gtransport.ConnPool 269 270 // Points back to the CallOptions field of the containing GenAiCacheClient 271 CallOptions **GenAiCacheCallOptions 272 273 // The gRPC API client. 274 genAiCacheClient aiplatformpb.GenAiCacheServiceClient 275 276 operationsClient longrunningpb.OperationsClient 277 278 iamPolicyClient iampb.IAMPolicyClient 279 280 locationsClient locationpb.LocationsClient 281 282 // The x-goog-* metadata to be sent with each request. 283 xGoogHeaders []string 284 285 logger *slog.Logger 286 } 287 288 // NewGenAiCacheClient creates a new gen ai cache service client based on gRPC. 289 // The returned client must be Closed when it is done being used to clean up its underlying connections. 290 // 291 // Service for managing Vertex AI’s CachedContent resource. 292 func NewGenAiCacheClient(ctx context.Context, opts ...option.ClientOption) (*GenAiCacheClient, error) { 293 clientOpts := defaultGenAiCacheGRPCClientOptions() 294 if newGenAiCacheClientHook != nil { 295 hookOpts, err := newGenAiCacheClientHook(ctx, clientHookParams{}) 296 if err != nil { 297 return nil, err 298 } 299 clientOpts = append(clientOpts, hookOpts...) 300 } 301 302 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 303 if err != nil { 304 return nil, err 305 } 306 client := GenAiCacheClient{CallOptions: defaultGenAiCacheCallOptions()} 307 308 c := &genAiCacheGRPCClient{ 309 connPool: connPool, 310 genAiCacheClient: aiplatformpb.NewGenAiCacheServiceClient(connPool), 311 CallOptions: &client.CallOptions, 312 logger: internaloption.GetLogger(opts), 313 operationsClient: longrunningpb.NewOperationsClient(connPool), 314 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 315 locationsClient: locationpb.NewLocationsClient(connPool), 316 } 317 c.setGoogleClientInfo() 318 319 client.internalClient = c 320 321 return &client, nil 322 } 323 324 // Connection returns a connection to the API service. 325 // 326 // Deprecated: Connections are now pooled so this method does not always 327 // return the same resource. 328 func (c *genAiCacheGRPCClient) Connection() *grpc.ClientConn { 329 return c.connPool.Conn() 330 } 331 332 // setGoogleClientInfo sets the name and version of the application in 333 // the `x-goog-api-client` header passed on each request. Intended for 334 // use by Google-written clients. 335 func (c *genAiCacheGRPCClient) setGoogleClientInfo(keyval ...string) { 336 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 337 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 338 c.xGoogHeaders = []string{ 339 "x-goog-api-client", gax.XGoogHeader(kv...), 340 } 341 } 342 343 // Close closes the connection to the API service. The user should invoke this when 344 // the client is no longer required. 345 func (c *genAiCacheGRPCClient) Close() error { 346 return c.connPool.Close() 347 } 348 349 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 350 type genAiCacheRESTClient struct { 351 // The http endpoint to connect to. 352 endpoint string 353 354 // The http client. 355 httpClient *http.Client 356 357 // The x-goog-* headers to be sent with each request. 358 xGoogHeaders []string 359 360 // Points back to the CallOptions field of the containing GenAiCacheClient 361 CallOptions **GenAiCacheCallOptions 362 363 logger *slog.Logger 364 } 365 366 // NewGenAiCacheRESTClient creates a new gen ai cache service rest client. 367 // 368 // Service for managing Vertex AI’s CachedContent resource. 369 func NewGenAiCacheRESTClient(ctx context.Context, opts ...option.ClientOption) (*GenAiCacheClient, error) { 370 clientOpts := append(defaultGenAiCacheRESTClientOptions(), opts...) 371 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 372 if err != nil { 373 return nil, err 374 } 375 376 callOpts := defaultGenAiCacheRESTCallOptions() 377 c := &genAiCacheRESTClient{ 378 endpoint: endpoint, 379 httpClient: httpClient, 380 CallOptions: &callOpts, 381 logger: internaloption.GetLogger(opts), 382 } 383 c.setGoogleClientInfo() 384 385 return &GenAiCacheClient{internalClient: c, CallOptions: callOpts}, nil 386 } 387 388 func defaultGenAiCacheRESTClientOptions() []option.ClientOption { 389 return []option.ClientOption{ 390 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 391 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 392 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 393 internaloption.WithDefaultUniverseDomain("googleapis.com"), 394 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 395 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 396 internaloption.EnableNewAuthLibrary(), 397 } 398 } 399 400 // setGoogleClientInfo sets the name and version of the application in 401 // the `x-goog-api-client` header passed on each request. Intended for 402 // use by Google-written clients. 403 func (c *genAiCacheRESTClient) setGoogleClientInfo(keyval ...string) { 404 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 405 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 406 c.xGoogHeaders = []string{ 407 "x-goog-api-client", gax.XGoogHeader(kv...), 408 } 409 } 410 411 // Close closes the connection to the API service. The user should invoke this when 412 // the client is no longer required. 413 func (c *genAiCacheRESTClient) Close() error { 414 // Replace httpClient with nil to force cleanup. 415 c.httpClient = nil 416 return nil 417 } 418 419 // Connection returns a connection to the API service. 420 // 421 // Deprecated: This method always returns nil. 422 func (c *genAiCacheRESTClient) Connection() *grpc.ClientConn { 423 return nil 424 } 425 func (c *genAiCacheGRPCClient) CreateCachedContent(ctx context.Context, req *aiplatformpb.CreateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 426 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 427 428 hds = append(c.xGoogHeaders, hds...) 429 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 430 opts = append((*c.CallOptions).CreateCachedContent[0:len((*c.CallOptions).CreateCachedContent):len((*c.CallOptions).CreateCachedContent)], opts...) 431 var resp *aiplatformpb.CachedContent 432 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 433 var err error 434 resp, err = executeRPC(ctx, c.genAiCacheClient.CreateCachedContent, req, settings.GRPC, c.logger, "CreateCachedContent") 435 return err 436 }, opts...) 437 if err != nil { 438 return nil, err 439 } 440 return resp, nil 441 } 442 443 func (c *genAiCacheGRPCClient) GetCachedContent(ctx context.Context, req *aiplatformpb.GetCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 444 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 445 446 hds = append(c.xGoogHeaders, hds...) 447 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 448 opts = append((*c.CallOptions).GetCachedContent[0:len((*c.CallOptions).GetCachedContent):len((*c.CallOptions).GetCachedContent)], opts...) 449 var resp *aiplatformpb.CachedContent 450 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 451 var err error 452 resp, err = executeRPC(ctx, c.genAiCacheClient.GetCachedContent, req, settings.GRPC, c.logger, "GetCachedContent") 453 return err 454 }, opts...) 455 if err != nil { 456 return nil, err 457 } 458 return resp, nil 459 } 460 461 func (c *genAiCacheGRPCClient) UpdateCachedContent(ctx context.Context, req *aiplatformpb.UpdateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 462 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "cached_content.name", url.QueryEscape(req.GetCachedContent().GetName()))} 463 464 hds = append(c.xGoogHeaders, hds...) 465 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 466 opts = append((*c.CallOptions).UpdateCachedContent[0:len((*c.CallOptions).UpdateCachedContent):len((*c.CallOptions).UpdateCachedContent)], opts...) 467 var resp *aiplatformpb.CachedContent 468 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 469 var err error 470 resp, err = executeRPC(ctx, c.genAiCacheClient.UpdateCachedContent, req, settings.GRPC, c.logger, "UpdateCachedContent") 471 return err 472 }, opts...) 473 if err != nil { 474 return nil, err 475 } 476 return resp, nil 477 } 478 479 func (c *genAiCacheGRPCClient) DeleteCachedContent(ctx context.Context, req *aiplatformpb.DeleteCachedContentRequest, opts ...gax.CallOption) error { 480 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 481 482 hds = append(c.xGoogHeaders, hds...) 483 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 484 opts = append((*c.CallOptions).DeleteCachedContent[0:len((*c.CallOptions).DeleteCachedContent):len((*c.CallOptions).DeleteCachedContent)], opts...) 485 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 486 var err error 487 _, err = executeRPC(ctx, c.genAiCacheClient.DeleteCachedContent, req, settings.GRPC, c.logger, "DeleteCachedContent") 488 return err 489 }, opts...) 490 return err 491 } 492 493 func (c *genAiCacheGRPCClient) ListCachedContents(ctx context.Context, req *aiplatformpb.ListCachedContentsRequest, opts ...gax.CallOption) *CachedContentIterator { 494 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 495 496 hds = append(c.xGoogHeaders, hds...) 497 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 498 opts = append((*c.CallOptions).ListCachedContents[0:len((*c.CallOptions).ListCachedContents):len((*c.CallOptions).ListCachedContents)], opts...) 499 it := &CachedContentIterator{} 500 req = proto.Clone(req).(*aiplatformpb.ListCachedContentsRequest) 501 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.CachedContent, string, error) { 502 resp := &aiplatformpb.ListCachedContentsResponse{} 503 if pageToken != "" { 504 req.PageToken = pageToken 505 } 506 if pageSize > math.MaxInt32 { 507 req.PageSize = math.MaxInt32 508 } else if pageSize != 0 { 509 req.PageSize = int32(pageSize) 510 } 511 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 512 var err error 513 resp, err = executeRPC(ctx, c.genAiCacheClient.ListCachedContents, req, settings.GRPC, c.logger, "ListCachedContents") 514 return err 515 }, opts...) 516 if err != nil { 517 return nil, "", err 518 } 519 520 it.Response = resp 521 return resp.GetCachedContents(), resp.GetNextPageToken(), nil 522 } 523 fetch := func(pageSize int, pageToken string) (string, error) { 524 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 525 if err != nil { 526 return "", err 527 } 528 it.items = append(it.items, items...) 529 return nextPageToken, nil 530 } 531 532 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 533 it.pageInfo.MaxSize = int(req.GetPageSize()) 534 it.pageInfo.Token = req.GetPageToken() 535 536 return it 537 } 538 539 func (c *genAiCacheGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 540 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 541 542 hds = append(c.xGoogHeaders, hds...) 543 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 544 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 545 var resp *locationpb.Location 546 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 547 var err error 548 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 549 return err 550 }, opts...) 551 if err != nil { 552 return nil, err 553 } 554 return resp, nil 555 } 556 557 func (c *genAiCacheGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 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).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 563 it := &LocationIterator{} 564 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 565 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 566 resp := &locationpb.ListLocationsResponse{} 567 if pageToken != "" { 568 req.PageToken = pageToken 569 } 570 if pageSize > math.MaxInt32 { 571 req.PageSize = math.MaxInt32 572 } else if pageSize != 0 { 573 req.PageSize = int32(pageSize) 574 } 575 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 576 var err error 577 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 578 return err 579 }, opts...) 580 if err != nil { 581 return nil, "", err 582 } 583 584 it.Response = resp 585 return resp.GetLocations(), resp.GetNextPageToken(), nil 586 } 587 fetch := func(pageSize int, pageToken string) (string, error) { 588 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 589 if err != nil { 590 return "", err 591 } 592 it.items = append(it.items, items...) 593 return nextPageToken, nil 594 } 595 596 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 597 it.pageInfo.MaxSize = int(req.GetPageSize()) 598 it.pageInfo.Token = req.GetPageToken() 599 600 return it 601 } 602 603 func (c *genAiCacheGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 604 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 605 606 hds = append(c.xGoogHeaders, hds...) 607 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 608 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 609 var resp *iampb.Policy 610 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 611 var err error 612 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 613 return err 614 }, opts...) 615 if err != nil { 616 return nil, err 617 } 618 return resp, nil 619 } 620 621 func (c *genAiCacheGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 622 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 623 624 hds = append(c.xGoogHeaders, hds...) 625 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 626 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 627 var resp *iampb.Policy 628 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 629 var err error 630 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 631 return err 632 }, opts...) 633 if err != nil { 634 return nil, err 635 } 636 return resp, nil 637 } 638 639 func (c *genAiCacheGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 640 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 641 642 hds = append(c.xGoogHeaders, hds...) 643 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 644 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 645 var resp *iampb.TestIamPermissionsResponse 646 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 647 var err error 648 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 649 return err 650 }, opts...) 651 if err != nil { 652 return nil, err 653 } 654 return resp, nil 655 } 656 657 func (c *genAiCacheGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 658 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 659 660 hds = append(c.xGoogHeaders, hds...) 661 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 662 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 663 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 664 var err error 665 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 666 return err 667 }, opts...) 668 return err 669 } 670 671 func (c *genAiCacheGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 672 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 673 674 hds = append(c.xGoogHeaders, hds...) 675 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 676 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 677 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 678 var err error 679 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 680 return err 681 }, opts...) 682 return err 683 } 684 685 func (c *genAiCacheGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 686 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 687 688 hds = append(c.xGoogHeaders, hds...) 689 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 690 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 691 var resp *longrunningpb.Operation 692 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 693 var err error 694 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 695 return err 696 }, opts...) 697 if err != nil { 698 return nil, err 699 } 700 return resp, nil 701 } 702 703 func (c *genAiCacheGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 704 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 705 706 hds = append(c.xGoogHeaders, hds...) 707 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 708 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 709 it := &OperationIterator{} 710 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 711 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 712 resp := &longrunningpb.ListOperationsResponse{} 713 if pageToken != "" { 714 req.PageToken = pageToken 715 } 716 if pageSize > math.MaxInt32 { 717 req.PageSize = math.MaxInt32 718 } else if pageSize != 0 { 719 req.PageSize = int32(pageSize) 720 } 721 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 722 var err error 723 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 724 return err 725 }, opts...) 726 if err != nil { 727 return nil, "", err 728 } 729 730 it.Response = resp 731 return resp.GetOperations(), resp.GetNextPageToken(), nil 732 } 733 fetch := func(pageSize int, pageToken string) (string, error) { 734 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 735 if err != nil { 736 return "", err 737 } 738 it.items = append(it.items, items...) 739 return nextPageToken, nil 740 } 741 742 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 743 it.pageInfo.MaxSize = int(req.GetPageSize()) 744 it.pageInfo.Token = req.GetPageToken() 745 746 return it 747 } 748 749 func (c *genAiCacheGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 750 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 751 752 hds = append(c.xGoogHeaders, hds...) 753 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 754 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 755 var resp *longrunningpb.Operation 756 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 757 var err error 758 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 759 return err 760 }, opts...) 761 if err != nil { 762 return nil, err 763 } 764 return resp, nil 765 } 766 767 // CreateCachedContent creates cached content, this call will initialize the cached content in the 768 // data storage, and users need to pay for the cache data storage. 769 func (c *genAiCacheRESTClient) CreateCachedContent(ctx context.Context, req *aiplatformpb.CreateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 770 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 771 body := req.GetCachedContent() 772 jsonReq, err := m.Marshal(body) 773 if err != nil { 774 return nil, err 775 } 776 777 baseUrl, err := url.Parse(c.endpoint) 778 if err != nil { 779 return nil, err 780 } 781 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/cachedContents", req.GetParent()) 782 783 params := url.Values{} 784 params.Add("$alt", "json;enum-encoding=int") 785 786 baseUrl.RawQuery = params.Encode() 787 788 // Build HTTP headers from client and context metadata. 789 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 790 791 hds = append(c.xGoogHeaders, hds...) 792 hds = append(hds, "Content-Type", "application/json") 793 headers := gax.BuildHeaders(ctx, hds...) 794 opts = append((*c.CallOptions).CreateCachedContent[0:len((*c.CallOptions).CreateCachedContent):len((*c.CallOptions).CreateCachedContent)], opts...) 795 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 796 resp := &aiplatformpb.CachedContent{} 797 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 798 if settings.Path != "" { 799 baseUrl.Path = settings.Path 800 } 801 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 802 if err != nil { 803 return err 804 } 805 httpReq = httpReq.WithContext(ctx) 806 httpReq.Header = headers 807 808 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateCachedContent") 809 if err != nil { 810 return err 811 } 812 813 if err := unm.Unmarshal(buf, resp); err != nil { 814 return err 815 } 816 817 return nil 818 }, opts...) 819 if e != nil { 820 return nil, e 821 } 822 return resp, nil 823 } 824 825 // GetCachedContent gets cached content configurations 826 func (c *genAiCacheRESTClient) GetCachedContent(ctx context.Context, req *aiplatformpb.GetCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 827 baseUrl, err := url.Parse(c.endpoint) 828 if err != nil { 829 return nil, err 830 } 831 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 832 833 params := url.Values{} 834 params.Add("$alt", "json;enum-encoding=int") 835 836 baseUrl.RawQuery = params.Encode() 837 838 // Build HTTP headers from client and context metadata. 839 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 840 841 hds = append(c.xGoogHeaders, hds...) 842 hds = append(hds, "Content-Type", "application/json") 843 headers := gax.BuildHeaders(ctx, hds...) 844 opts = append((*c.CallOptions).GetCachedContent[0:len((*c.CallOptions).GetCachedContent):len((*c.CallOptions).GetCachedContent)], opts...) 845 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 846 resp := &aiplatformpb.CachedContent{} 847 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 848 if settings.Path != "" { 849 baseUrl.Path = settings.Path 850 } 851 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 852 if err != nil { 853 return err 854 } 855 httpReq = httpReq.WithContext(ctx) 856 httpReq.Header = headers 857 858 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCachedContent") 859 if err != nil { 860 return err 861 } 862 863 if err := unm.Unmarshal(buf, resp); err != nil { 864 return err 865 } 866 867 return nil 868 }, opts...) 869 if e != nil { 870 return nil, e 871 } 872 return resp, nil 873 } 874 875 // UpdateCachedContent updates cached content configurations 876 func (c *genAiCacheRESTClient) UpdateCachedContent(ctx context.Context, req *aiplatformpb.UpdateCachedContentRequest, opts ...gax.CallOption) (*aiplatformpb.CachedContent, error) { 877 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 878 body := req.GetCachedContent() 879 jsonReq, err := m.Marshal(body) 880 if err != nil { 881 return nil, err 882 } 883 884 baseUrl, err := url.Parse(c.endpoint) 885 if err != nil { 886 return nil, err 887 } 888 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetCachedContent().GetName()) 889 890 params := url.Values{} 891 params.Add("$alt", "json;enum-encoding=int") 892 if req.GetUpdateMask() != nil { 893 field, err := protojson.Marshal(req.GetUpdateMask()) 894 if err != nil { 895 return nil, err 896 } 897 params.Add("updateMask", string(field[1:len(field)-1])) 898 } 899 900 baseUrl.RawQuery = params.Encode() 901 902 // Build HTTP headers from client and context metadata. 903 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "cached_content.name", url.QueryEscape(req.GetCachedContent().GetName()))} 904 905 hds = append(c.xGoogHeaders, hds...) 906 hds = append(hds, "Content-Type", "application/json") 907 headers := gax.BuildHeaders(ctx, hds...) 908 opts = append((*c.CallOptions).UpdateCachedContent[0:len((*c.CallOptions).UpdateCachedContent):len((*c.CallOptions).UpdateCachedContent)], opts...) 909 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 910 resp := &aiplatformpb.CachedContent{} 911 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 912 if settings.Path != "" { 913 baseUrl.Path = settings.Path 914 } 915 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) 916 if err != nil { 917 return err 918 } 919 httpReq = httpReq.WithContext(ctx) 920 httpReq.Header = headers 921 922 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateCachedContent") 923 if err != nil { 924 return err 925 } 926 927 if err := unm.Unmarshal(buf, resp); err != nil { 928 return err 929 } 930 931 return nil 932 }, opts...) 933 if e != nil { 934 return nil, e 935 } 936 return resp, nil 937 } 938 939 // DeleteCachedContent deletes cached content 940 func (c *genAiCacheRESTClient) DeleteCachedContent(ctx context.Context, req *aiplatformpb.DeleteCachedContentRequest, opts ...gax.CallOption) error { 941 baseUrl, err := url.Parse(c.endpoint) 942 if err != nil { 943 return err 944 } 945 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 946 947 params := url.Values{} 948 params.Add("$alt", "json;enum-encoding=int") 949 950 baseUrl.RawQuery = params.Encode() 951 952 // Build HTTP headers from client and context metadata. 953 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 954 955 hds = append(c.xGoogHeaders, hds...) 956 hds = append(hds, "Content-Type", "application/json") 957 headers := gax.BuildHeaders(ctx, hds...) 958 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 959 if settings.Path != "" { 960 baseUrl.Path = settings.Path 961 } 962 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 963 if err != nil { 964 return err 965 } 966 httpReq = httpReq.WithContext(ctx) 967 httpReq.Header = headers 968 969 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteCachedContent") 970 return err 971 }, opts...) 972 } 973 974 // ListCachedContents lists cached contents in a project 975 func (c *genAiCacheRESTClient) ListCachedContents(ctx context.Context, req *aiplatformpb.ListCachedContentsRequest, opts ...gax.CallOption) *CachedContentIterator { 976 it := &CachedContentIterator{} 977 req = proto.Clone(req).(*aiplatformpb.ListCachedContentsRequest) 978 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 979 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.CachedContent, string, error) { 980 resp := &aiplatformpb.ListCachedContentsResponse{} 981 if pageToken != "" { 982 req.PageToken = pageToken 983 } 984 if pageSize > math.MaxInt32 { 985 req.PageSize = math.MaxInt32 986 } else if pageSize != 0 { 987 req.PageSize = int32(pageSize) 988 } 989 baseUrl, err := url.Parse(c.endpoint) 990 if err != nil { 991 return nil, "", err 992 } 993 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/cachedContents", req.GetParent()) 994 995 params := url.Values{} 996 params.Add("$alt", "json;enum-encoding=int") 997 if req.GetPageSize() != 0 { 998 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 999 } 1000 if req.GetPageToken() != "" { 1001 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1002 } 1003 1004 baseUrl.RawQuery = params.Encode() 1005 1006 // Build HTTP headers from client and context metadata. 1007 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1008 headers := gax.BuildHeaders(ctx, hds...) 1009 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1010 if settings.Path != "" { 1011 baseUrl.Path = settings.Path 1012 } 1013 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1014 if err != nil { 1015 return err 1016 } 1017 httpReq.Header = headers 1018 1019 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListCachedContents") 1020 if err != nil { 1021 return err 1022 } 1023 if err := unm.Unmarshal(buf, resp); err != nil { 1024 return err 1025 } 1026 1027 return nil 1028 }, opts...) 1029 if e != nil { 1030 return nil, "", e 1031 } 1032 it.Response = resp 1033 return resp.GetCachedContents(), resp.GetNextPageToken(), nil 1034 } 1035 1036 fetch := func(pageSize int, pageToken string) (string, error) { 1037 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1038 if err != nil { 1039 return "", err 1040 } 1041 it.items = append(it.items, items...) 1042 return nextPageToken, nil 1043 } 1044 1045 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1046 it.pageInfo.MaxSize = int(req.GetPageSize()) 1047 it.pageInfo.Token = req.GetPageToken() 1048 1049 return it 1050 } 1051 1052 // GetLocation gets information about a location. 1053 func (c *genAiCacheRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1054 baseUrl, err := url.Parse(c.endpoint) 1055 if err != nil { 1056 return nil, err 1057 } 1058 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1059 1060 params := url.Values{} 1061 params.Add("$alt", "json;enum-encoding=int") 1062 1063 baseUrl.RawQuery = params.Encode() 1064 1065 // Build HTTP headers from client and context metadata. 1066 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1067 1068 hds = append(c.xGoogHeaders, hds...) 1069 hds = append(hds, "Content-Type", "application/json") 1070 headers := gax.BuildHeaders(ctx, hds...) 1071 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1072 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1073 resp := &locationpb.Location{} 1074 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1075 if settings.Path != "" { 1076 baseUrl.Path = settings.Path 1077 } 1078 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1079 if err != nil { 1080 return err 1081 } 1082 httpReq = httpReq.WithContext(ctx) 1083 httpReq.Header = headers 1084 1085 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1086 if err != nil { 1087 return err 1088 } 1089 1090 if err := unm.Unmarshal(buf, resp); err != nil { 1091 return err 1092 } 1093 1094 return nil 1095 }, opts...) 1096 if e != nil { 1097 return nil, e 1098 } 1099 return resp, nil 1100 } 1101 1102 // ListLocations lists information about the supported locations for this service. 1103 func (c *genAiCacheRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1104 it := &LocationIterator{} 1105 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1106 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1107 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1108 resp := &locationpb.ListLocationsResponse{} 1109 if pageToken != "" { 1110 req.PageToken = pageToken 1111 } 1112 if pageSize > math.MaxInt32 { 1113 req.PageSize = math.MaxInt32 1114 } else if pageSize != 0 { 1115 req.PageSize = int32(pageSize) 1116 } 1117 baseUrl, err := url.Parse(c.endpoint) 1118 if err != nil { 1119 return nil, "", err 1120 } 1121 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1122 1123 params := url.Values{} 1124 params.Add("$alt", "json;enum-encoding=int") 1125 if req.GetFilter() != "" { 1126 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1127 } 1128 if req.GetPageSize() != 0 { 1129 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1130 } 1131 if req.GetPageToken() != "" { 1132 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1133 } 1134 1135 baseUrl.RawQuery = params.Encode() 1136 1137 // Build HTTP headers from client and context metadata. 1138 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1139 headers := gax.BuildHeaders(ctx, hds...) 1140 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1141 if settings.Path != "" { 1142 baseUrl.Path = settings.Path 1143 } 1144 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1145 if err != nil { 1146 return err 1147 } 1148 httpReq.Header = headers 1149 1150 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1151 if err != nil { 1152 return err 1153 } 1154 if err := unm.Unmarshal(buf, resp); err != nil { 1155 return err 1156 } 1157 1158 return nil 1159 }, opts...) 1160 if e != nil { 1161 return nil, "", e 1162 } 1163 it.Response = resp 1164 return resp.GetLocations(), resp.GetNextPageToken(), nil 1165 } 1166 1167 fetch := func(pageSize int, pageToken string) (string, error) { 1168 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1169 if err != nil { 1170 return "", err 1171 } 1172 it.items = append(it.items, items...) 1173 return nextPageToken, nil 1174 } 1175 1176 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1177 it.pageInfo.MaxSize = int(req.GetPageSize()) 1178 it.pageInfo.Token = req.GetPageToken() 1179 1180 return it 1181 } 1182 1183 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1184 // if the resource exists and does not have a policy set. 1185 func (c *genAiCacheRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1186 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1187 jsonReq, err := m.Marshal(req) 1188 if err != nil { 1189 return nil, err 1190 } 1191 1192 baseUrl, err := url.Parse(c.endpoint) 1193 if err != nil { 1194 return nil, err 1195 } 1196 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1197 1198 params := url.Values{} 1199 params.Add("$alt", "json;enum-encoding=int") 1200 1201 baseUrl.RawQuery = params.Encode() 1202 1203 // Build HTTP headers from client and context metadata. 1204 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1205 1206 hds = append(c.xGoogHeaders, hds...) 1207 hds = append(hds, "Content-Type", "application/json") 1208 headers := gax.BuildHeaders(ctx, hds...) 1209 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 1210 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1211 resp := &iampb.Policy{} 1212 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1213 if settings.Path != "" { 1214 baseUrl.Path = settings.Path 1215 } 1216 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1217 if err != nil { 1218 return err 1219 } 1220 httpReq = httpReq.WithContext(ctx) 1221 httpReq.Header = headers 1222 1223 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 1224 if err != nil { 1225 return err 1226 } 1227 1228 if err := unm.Unmarshal(buf, resp); err != nil { 1229 return err 1230 } 1231 1232 return nil 1233 }, opts...) 1234 if e != nil { 1235 return nil, e 1236 } 1237 return resp, nil 1238 } 1239 1240 // SetIamPolicy sets the access control policy on the specified resource. Replaces 1241 // any existing policy. 1242 // 1243 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 1244 // errors. 1245 func (c *genAiCacheRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1246 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1247 jsonReq, err := m.Marshal(req) 1248 if err != nil { 1249 return nil, err 1250 } 1251 1252 baseUrl, err := url.Parse(c.endpoint) 1253 if err != nil { 1254 return nil, err 1255 } 1256 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 1257 1258 params := url.Values{} 1259 params.Add("$alt", "json;enum-encoding=int") 1260 1261 baseUrl.RawQuery = params.Encode() 1262 1263 // Build HTTP headers from client and context metadata. 1264 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1265 1266 hds = append(c.xGoogHeaders, hds...) 1267 hds = append(hds, "Content-Type", "application/json") 1268 headers := gax.BuildHeaders(ctx, hds...) 1269 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 1270 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1271 resp := &iampb.Policy{} 1272 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1273 if settings.Path != "" { 1274 baseUrl.Path = settings.Path 1275 } 1276 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1277 if err != nil { 1278 return err 1279 } 1280 httpReq = httpReq.WithContext(ctx) 1281 httpReq.Header = headers 1282 1283 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 1284 if err != nil { 1285 return err 1286 } 1287 1288 if err := unm.Unmarshal(buf, resp); err != nil { 1289 return err 1290 } 1291 1292 return nil 1293 }, opts...) 1294 if e != nil { 1295 return nil, e 1296 } 1297 return resp, nil 1298 } 1299 1300 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 1301 // resource does not exist, this will return an empty set of 1302 // permissions, not a NOT_FOUND error. 1303 // 1304 // Note: This operation is designed to be used for building 1305 // permission-aware UIs and command-line tools, not for authorization 1306 // checking. This operation may “fail open” without warning. 1307 func (c *genAiCacheRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 1308 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1309 jsonReq, err := m.Marshal(req) 1310 if err != nil { 1311 return nil, err 1312 } 1313 1314 baseUrl, err := url.Parse(c.endpoint) 1315 if err != nil { 1316 return nil, err 1317 } 1318 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 1319 1320 params := url.Values{} 1321 params.Add("$alt", "json;enum-encoding=int") 1322 1323 baseUrl.RawQuery = params.Encode() 1324 1325 // Build HTTP headers from client and context metadata. 1326 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1327 1328 hds = append(c.xGoogHeaders, hds...) 1329 hds = append(hds, "Content-Type", "application/json") 1330 headers := gax.BuildHeaders(ctx, hds...) 1331 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 1332 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1333 resp := &iampb.TestIamPermissionsResponse{} 1334 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1335 if settings.Path != "" { 1336 baseUrl.Path = settings.Path 1337 } 1338 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1339 if err != nil { 1340 return err 1341 } 1342 httpReq = httpReq.WithContext(ctx) 1343 httpReq.Header = headers 1344 1345 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 1346 if err != nil { 1347 return err 1348 } 1349 1350 if err := unm.Unmarshal(buf, resp); err != nil { 1351 return err 1352 } 1353 1354 return nil 1355 }, opts...) 1356 if e != nil { 1357 return nil, e 1358 } 1359 return resp, nil 1360 } 1361 1362 // CancelOperation is a utility method from google.longrunning.Operations. 1363 func (c *genAiCacheRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 1364 baseUrl, err := url.Parse(c.endpoint) 1365 if err != nil { 1366 return err 1367 } 1368 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 1369 1370 params := url.Values{} 1371 params.Add("$alt", "json;enum-encoding=int") 1372 1373 baseUrl.RawQuery = params.Encode() 1374 1375 // Build HTTP headers from client and context metadata. 1376 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1377 1378 hds = append(c.xGoogHeaders, hds...) 1379 hds = append(hds, "Content-Type", "application/json") 1380 headers := gax.BuildHeaders(ctx, hds...) 1381 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1382 if settings.Path != "" { 1383 baseUrl.Path = settings.Path 1384 } 1385 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1386 if err != nil { 1387 return err 1388 } 1389 httpReq = httpReq.WithContext(ctx) 1390 httpReq.Header = headers 1391 1392 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 1393 return err 1394 }, opts...) 1395 } 1396 1397 // DeleteOperation is a utility method from google.longrunning.Operations. 1398 func (c *genAiCacheRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 1399 baseUrl, err := url.Parse(c.endpoint) 1400 if err != nil { 1401 return err 1402 } 1403 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1404 1405 params := url.Values{} 1406 params.Add("$alt", "json;enum-encoding=int") 1407 1408 baseUrl.RawQuery = params.Encode() 1409 1410 // Build HTTP headers from client and context metadata. 1411 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1412 1413 hds = append(c.xGoogHeaders, hds...) 1414 hds = append(hds, "Content-Type", "application/json") 1415 headers := gax.BuildHeaders(ctx, hds...) 1416 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1417 if settings.Path != "" { 1418 baseUrl.Path = settings.Path 1419 } 1420 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1421 if err != nil { 1422 return err 1423 } 1424 httpReq = httpReq.WithContext(ctx) 1425 httpReq.Header = headers 1426 1427 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 1428 return err 1429 }, opts...) 1430 } 1431 1432 // GetOperation is a utility method from google.longrunning.Operations. 1433 func (c *genAiCacheRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1434 baseUrl, err := url.Parse(c.endpoint) 1435 if err != nil { 1436 return nil, err 1437 } 1438 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1439 1440 params := url.Values{} 1441 params.Add("$alt", "json;enum-encoding=int") 1442 1443 baseUrl.RawQuery = params.Encode() 1444 1445 // Build HTTP headers from client and context metadata. 1446 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1447 1448 hds = append(c.xGoogHeaders, hds...) 1449 hds = append(hds, "Content-Type", "application/json") 1450 headers := gax.BuildHeaders(ctx, hds...) 1451 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 1452 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1453 resp := &longrunningpb.Operation{} 1454 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1455 if settings.Path != "" { 1456 baseUrl.Path = settings.Path 1457 } 1458 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1459 if err != nil { 1460 return err 1461 } 1462 httpReq = httpReq.WithContext(ctx) 1463 httpReq.Header = headers 1464 1465 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 1466 if err != nil { 1467 return err 1468 } 1469 1470 if err := unm.Unmarshal(buf, resp); err != nil { 1471 return err 1472 } 1473 1474 return nil 1475 }, opts...) 1476 if e != nil { 1477 return nil, e 1478 } 1479 return resp, nil 1480 } 1481 1482 // ListOperations is a utility method from google.longrunning.Operations. 1483 func (c *genAiCacheRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1484 it := &OperationIterator{} 1485 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1486 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1487 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1488 resp := &longrunningpb.ListOperationsResponse{} 1489 if pageToken != "" { 1490 req.PageToken = pageToken 1491 } 1492 if pageSize > math.MaxInt32 { 1493 req.PageSize = math.MaxInt32 1494 } else if pageSize != 0 { 1495 req.PageSize = int32(pageSize) 1496 } 1497 baseUrl, err := url.Parse(c.endpoint) 1498 if err != nil { 1499 return nil, "", err 1500 } 1501 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 1502 1503 params := url.Values{} 1504 params.Add("$alt", "json;enum-encoding=int") 1505 if req.GetFilter() != "" { 1506 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1507 } 1508 if req.GetPageSize() != 0 { 1509 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1510 } 1511 if req.GetPageToken() != "" { 1512 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1513 } 1514 1515 baseUrl.RawQuery = params.Encode() 1516 1517 // Build HTTP headers from client and context metadata. 1518 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1519 headers := gax.BuildHeaders(ctx, hds...) 1520 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1521 if settings.Path != "" { 1522 baseUrl.Path = settings.Path 1523 } 1524 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1525 if err != nil { 1526 return err 1527 } 1528 httpReq.Header = headers 1529 1530 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 1531 if err != nil { 1532 return err 1533 } 1534 if err := unm.Unmarshal(buf, resp); err != nil { 1535 return err 1536 } 1537 1538 return nil 1539 }, opts...) 1540 if e != nil { 1541 return nil, "", e 1542 } 1543 it.Response = resp 1544 return resp.GetOperations(), resp.GetNextPageToken(), nil 1545 } 1546 1547 fetch := func(pageSize int, pageToken string) (string, error) { 1548 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1549 if err != nil { 1550 return "", err 1551 } 1552 it.items = append(it.items, items...) 1553 return nextPageToken, nil 1554 } 1555 1556 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1557 it.pageInfo.MaxSize = int(req.GetPageSize()) 1558 it.pageInfo.Token = req.GetPageToken() 1559 1560 return it 1561 } 1562 1563 // WaitOperation is a utility method from google.longrunning.Operations. 1564 func (c *genAiCacheRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1565 baseUrl, err := url.Parse(c.endpoint) 1566 if err != nil { 1567 return nil, err 1568 } 1569 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 1570 1571 params := url.Values{} 1572 params.Add("$alt", "json;enum-encoding=int") 1573 if req.GetTimeout() != nil { 1574 field, err := protojson.Marshal(req.GetTimeout()) 1575 if err != nil { 1576 return nil, err 1577 } 1578 params.Add("timeout", string(field[1:len(field)-1])) 1579 } 1580 1581 baseUrl.RawQuery = params.Encode() 1582 1583 // Build HTTP headers from client and context metadata. 1584 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1585 1586 hds = append(c.xGoogHeaders, hds...) 1587 hds = append(hds, "Content-Type", "application/json") 1588 headers := gax.BuildHeaders(ctx, hds...) 1589 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1590 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1591 resp := &longrunningpb.Operation{} 1592 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1593 if settings.Path != "" { 1594 baseUrl.Path = settings.Path 1595 } 1596 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1597 if err != nil { 1598 return err 1599 } 1600 httpReq = httpReq.WithContext(ctx) 1601 httpReq.Header = headers 1602 1603 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 1604 if err != nil { 1605 return err 1606 } 1607 1608 if err := unm.Unmarshal(buf, resp); err != nil { 1609 return err 1610 } 1611 1612 return nil 1613 }, opts...) 1614 if e != nil { 1615 return nil, e 1616 } 1617 return resp, nil 1618 }