Debian Codegraph @

retail/apiv2beta/conversational_search_client.go

raw symbols SCIP
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 retail
18
19 import (
20 "bytes"
21 "context"
22 "errors"
23 "fmt"
24 "log/slog"
25 "math"
26 "net/http"
27 "net/url"
28 "time"
29
30 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
31 retailpb "cloud.google.com/go/retail/apiv2beta/retailpb"
32 gax "github.com/googleapis/gax-go/v2"
33 "google.golang.org/api/iterator"
34 "google.golang.org/api/option"
35 "google.golang.org/api/option/internaloption"
36 gtransport "google.golang.org/api/transport/grpc"
37 httptransport "google.golang.org/api/transport/http"
38 "google.golang.org/grpc"
39 "google.golang.org/grpc/codes"
40 "google.golang.org/grpc/metadata"
41 "google.golang.org/protobuf/encoding/protojson"
42 "google.golang.org/protobuf/proto"
43 )
44
45 var newConversationalSearchClientHook clientHook
46
47 // ConversationalSearchCallOptions contains the retry settings for each method of ConversationalSearchClient.
48 type ConversationalSearchCallOptions struct {
49 ConversationalSearch []gax.CallOption
50 GetOperation []gax.CallOption
51 ListOperations []gax.CallOption
52 }
53
54 func defaultConversationalSearchGRPCClientOptions() []option.ClientOption {
55 return []option.ClientOption{
56 internaloption.WithDefaultEndpoint("retail.googleapis.com:443"),
57 internaloption.WithDefaultEndpointTemplate("retail.UNIVERSE_DOMAIN:443"),
58 internaloption.WithDefaultMTLSEndpoint("retail.mtls.googleapis.com:443"),
59 internaloption.WithDefaultUniverseDomain("googleapis.com"),
60 internaloption.WithDefaultAudience("https://retail.googleapis.com/"),
61 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
62 internaloption.EnableJwtWithScope(),
63 internaloption.EnableNewAuthLibrary(),
64 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
65 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
66 }
67 }
68
69 func defaultConversationalSearchCallOptions() *ConversationalSearchCallOptions {
70 return &ConversationalSearchCallOptions{
71 ConversationalSearch: []gax.CallOption{},
72 GetOperation: []gax.CallOption{},
73 ListOperations: []gax.CallOption{
74 gax.WithTimeout(300000 * time.Millisecond),
75 gax.WithRetry(func() gax.Retryer {
76 return gax.OnCodes([]codes.Code{
77 codes.Unavailable,
78 codes.DeadlineExceeded,
79 }, gax.Backoff{
80 Initial: 100 * time.Millisecond,
81 Max: 300000 * time.Millisecond,
82 Multiplier: 1.30,
83 })
84 }),
85 },
86 }
87 }
88
89 func defaultConversationalSearchRESTCallOptions() *ConversationalSearchCallOptions {
90 return &ConversationalSearchCallOptions{
91 ConversationalSearch: []gax.CallOption{},
92 GetOperation: []gax.CallOption{},
93 ListOperations: []gax.CallOption{
94 gax.WithTimeout(300000 * time.Millisecond),
95 gax.WithRetry(func() gax.Retryer {
96 return gax.OnHTTPCodes(gax.Backoff{
97 Initial: 100 * time.Millisecond,
98 Max: 300000 * time.Millisecond,
99 Multiplier: 1.30,
100 },
101 http.StatusServiceUnavailable,
102 http.StatusGatewayTimeout)
103 }),
104 },
105 }
106 }
107
108 // internalConversationalSearchClient is an interface that defines the methods available from Vertex AI Search for commerce API.
109 type internalConversationalSearchClient interface {
110 Close() error
111 setGoogleClientInfo(...string)
112 Connection() *grpc.ClientConn
113 ConversationalSearch(context.Context, *retailpb.ConversationalSearchRequest, ...gax.CallOption) (retailpb.ConversationalSearchService_ConversationalSearchClient, error)
114 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
115 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
116 }
117
118 // ConversationalSearchClient is a client for interacting with Vertex AI Search for commerce API.
119 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
120 //
121 // Service for retail conversational search.
122 //
123 // This feature is only available for users who have Retail Conversational
124 // Search enabled. Enable Retail Conversational Search on Cloud Console
125 // before using this feature.
126 type ConversationalSearchClient struct {
127 // The internal transport-dependent client.
128 internalClient internalConversationalSearchClient
129
130 // The call options for this service.
131 CallOptions *ConversationalSearchCallOptions
132 }
133
134 // Wrapper methods routed to the internal client.
135
136 // Close closes the connection to the API service. The user should invoke this when
137 // the client is no longer required.
138 func (c *ConversationalSearchClient) Close() error {
139 return c.internalClient.Close()
140 }
141
142 // setGoogleClientInfo sets the name and version of the application in
143 // the `x-goog-api-client` header passed on each request. Intended for
144 // use by Google-written clients.
145 func (c *ConversationalSearchClient) setGoogleClientInfo(keyval ...string) {
146 c.internalClient.setGoogleClientInfo(keyval...)
147 }
148
149 // Connection returns a connection to the API service.
150 //
151 // Deprecated: Connections are now pooled so this method does not always
152 // return the same resource.
153 func (c *ConversationalSearchClient) Connection() *grpc.ClientConn {
154 return c.internalClient.Connection()
155 }
156
157 // ConversationalSearch performs a conversational search.
158 //
159 // This feature is only available for users who have Conversational Search
160 // enabled.
161 func (c *ConversationalSearchClient) ConversationalSearch(ctx context.Context, req *retailpb.ConversationalSearchRequest, opts ...gax.CallOption) (retailpb.ConversationalSearchService_ConversationalSearchClient, error) {
162 return c.internalClient.ConversationalSearch(ctx, req, opts...)
163 }
164
165 // GetOperation is a utility method from google.longrunning.Operations.
166 func (c *ConversationalSearchClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
167 return c.internalClient.GetOperation(ctx, req, opts...)
168 }
169
170 // ListOperations is a utility method from google.longrunning.Operations.
171 func (c *ConversationalSearchClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
172 return c.internalClient.ListOperations(ctx, req, opts...)
173 }
174
175 // conversationalSearchGRPCClient is a client for interacting with Vertex AI Search for commerce API over gRPC transport.
176 //
177 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
178 type conversationalSearchGRPCClient struct {
179 // Connection pool of gRPC connections to the service.
180 connPool gtransport.ConnPool
181
182 // Points back to the CallOptions field of the containing ConversationalSearchClient
183 CallOptions **ConversationalSearchCallOptions
184
185 // The gRPC API client.
186 conversationalSearchClient retailpb.ConversationalSearchServiceClient
187
188 operationsClient longrunningpb.OperationsClient
189
190 // The x-goog-* metadata to be sent with each request.
191 xGoogHeaders []string
192
193 logger *slog.Logger
194 }
195
196 // NewConversationalSearchClient creates a new conversational search service client based on gRPC.
197 // The returned client must be Closed when it is done being used to clean up its underlying connections.
198 //
199 // Service for retail conversational search.
200 //
201 // This feature is only available for users who have Retail Conversational
202 // Search enabled. Enable Retail Conversational Search on Cloud Console
203 // before using this feature.
204 func NewConversationalSearchClient(ctx context.Context, opts ...option.ClientOption) (*ConversationalSearchClient, error) {
205 clientOpts := defaultConversationalSearchGRPCClientOptions()
206 if newConversationalSearchClientHook != nil {
207 hookOpts, err := newConversationalSearchClientHook(ctx, clientHookParams{})
208 if err != nil {
209 return nil, err
210 }
211 clientOpts = append(clientOpts, hookOpts...)
212 }
213
214 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
215 if err != nil {
216 return nil, err
217 }
218 client := ConversationalSearchClient{CallOptions: defaultConversationalSearchCallOptions()}
219
220 c := &conversationalSearchGRPCClient{
221 connPool: connPool,
222 conversationalSearchClient: retailpb.NewConversationalSearchServiceClient(connPool),
223 CallOptions: &client.CallOptions,
224 logger: internaloption.GetLogger(opts),
225 operationsClient: longrunningpb.NewOperationsClient(connPool),
226 }
227 c.setGoogleClientInfo()
228
229 client.internalClient = c
230
231 return &client, nil
232 }
233
234 // Connection returns a connection to the API service.
235 //
236 // Deprecated: Connections are now pooled so this method does not always
237 // return the same resource.
238 func (c *conversationalSearchGRPCClient) Connection() *grpc.ClientConn {
239 return c.connPool.Conn()
240 }
241
242 // setGoogleClientInfo sets the name and version of the application in
243 // the `x-goog-api-client` header passed on each request. Intended for
244 // use by Google-written clients.
245 func (c *conversationalSearchGRPCClient) setGoogleClientInfo(keyval ...string) {
246 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
247 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
248 c.xGoogHeaders = []string{
249 "x-goog-api-client", gax.XGoogHeader(kv...),
250 }
251 }
252
253 // Close closes the connection to the API service. The user should invoke this when
254 // the client is no longer required.
255 func (c *conversationalSearchGRPCClient) Close() error {
256 return c.connPool.Close()
257 }
258
259 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
260 type conversationalSearchRESTClient struct {
261 // The http endpoint to connect to.
262 endpoint string
263
264 // The http client.
265 httpClient *http.Client
266
267 // The x-goog-* headers to be sent with each request.
268 xGoogHeaders []string
269
270 // Points back to the CallOptions field of the containing ConversationalSearchClient
271 CallOptions **ConversationalSearchCallOptions
272
273 logger *slog.Logger
274 }
275
276 // NewConversationalSearchRESTClient creates a new conversational search service rest client.
277 //
278 // Service for retail conversational search.
279 //
280 // This feature is only available for users who have Retail Conversational
281 // Search enabled. Enable Retail Conversational Search on Cloud Console
282 // before using this feature.
283 func NewConversationalSearchRESTClient(ctx context.Context, opts ...option.ClientOption) (*ConversationalSearchClient, error) {
284 clientOpts := append(defaultConversationalSearchRESTClientOptions(), opts...)
285 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
286 if err != nil {
287 return nil, err
288 }
289
290 callOpts := defaultConversationalSearchRESTCallOptions()
291 c := &conversationalSearchRESTClient{
292 endpoint: endpoint,
293 httpClient: httpClient,
294 CallOptions: &callOpts,
295 logger: internaloption.GetLogger(opts),
296 }
297 c.setGoogleClientInfo()
298
299 return &ConversationalSearchClient{internalClient: c, CallOptions: callOpts}, nil
300 }
301
302 func defaultConversationalSearchRESTClientOptions() []option.ClientOption {
303 return []option.ClientOption{
304 internaloption.WithDefaultEndpoint("https://retail.googleapis.com"),
305 internaloption.WithDefaultEndpointTemplate("https://retail.UNIVERSE_DOMAIN"),
306 internaloption.WithDefaultMTLSEndpoint("https://retail.mtls.googleapis.com"),
307 internaloption.WithDefaultUniverseDomain("googleapis.com"),
308 internaloption.WithDefaultAudience("https://retail.googleapis.com/"),
309 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
310 internaloption.EnableNewAuthLibrary(),
311 }
312 }
313
314 // setGoogleClientInfo sets the name and version of the application in
315 // the `x-goog-api-client` header passed on each request. Intended for
316 // use by Google-written clients.
317 func (c *conversationalSearchRESTClient) setGoogleClientInfo(keyval ...string) {
318 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
319 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
320 c.xGoogHeaders = []string{
321 "x-goog-api-client", gax.XGoogHeader(kv...),
322 }
323 }
324
325 // Close closes the connection to the API service. The user should invoke this when
326 // the client is no longer required.
327 func (c *conversationalSearchRESTClient) Close() error {
328 // Replace httpClient with nil to force cleanup.
329 c.httpClient = nil
330 return nil
331 }
332
333 // Connection returns a connection to the API service.
334 //
335 // Deprecated: This method always returns nil.
336 func (c *conversationalSearchRESTClient) Connection() *grpc.ClientConn {
337 return nil
338 }
339 func (c *conversationalSearchGRPCClient) ConversationalSearch(ctx context.Context, req *retailpb.ConversationalSearchRequest, opts ...gax.CallOption) (retailpb.ConversationalSearchService_ConversationalSearchClient, error) {
340 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "placement", url.QueryEscape(req.GetPlacement()))}
341
342 hds = append(c.xGoogHeaders, hds...)
343 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
344 opts = append((*c.CallOptions).ConversationalSearch[0:len((*c.CallOptions).ConversationalSearch):len((*c.CallOptions).ConversationalSearch)], opts...)
345 var resp retailpb.ConversationalSearchService_ConversationalSearchClient
346 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
347 var err error
348 c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "ConversationalSearch")
349 resp, err = c.conversationalSearchClient.ConversationalSearch(ctx, req, settings.GRPC...)
350 c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "ConversationalSearch")
351 return err
352 }, opts...)
353 if err != nil {
354 return nil, err
355 }
356 return resp, nil
357 }
358
359 func (c *conversationalSearchGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
360 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
361
362 hds = append(c.xGoogHeaders, hds...)
363 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
364 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
365 var resp *longrunningpb.Operation
366 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
367 var err error
368 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
369 return err
370 }, opts...)
371 if err != nil {
372 return nil, err
373 }
374 return resp, nil
375 }
376
377 func (c *conversationalSearchGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
378 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
379
380 hds = append(c.xGoogHeaders, hds...)
381 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
382 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
383 it := &OperationIterator{}
384 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
385 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
386 resp := &longrunningpb.ListOperationsResponse{}
387 if pageToken != "" {
388 req.PageToken = pageToken
389 }
390 if pageSize > math.MaxInt32 {
391 req.PageSize = math.MaxInt32
392 } else if pageSize != 0 {
393 req.PageSize = int32(pageSize)
394 }
395 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
396 var err error
397 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
398 return err
399 }, opts...)
400 if err != nil {
401 return nil, "", err
402 }
403
404 it.Response = resp
405 return resp.GetOperations(), resp.GetNextPageToken(), nil
406 }
407 fetch := func(pageSize int, pageToken string) (string, error) {
408 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
409 if err != nil {
410 return "", err
411 }
412 it.items = append(it.items, items...)
413 return nextPageToken, nil
414 }
415
416 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
417 it.pageInfo.MaxSize = int(req.GetPageSize())
418 it.pageInfo.Token = req.GetPageToken()
419
420 return it
421 }
422
423 // ConversationalSearch performs a conversational search.
424 //
425 // This feature is only available for users who have Conversational Search
426 // enabled.
427 func (c *conversationalSearchRESTClient) ConversationalSearch(ctx context.Context, req *retailpb.ConversationalSearchRequest, opts ...gax.CallOption) (retailpb.ConversationalSearchService_ConversationalSearchClient, error) {
428 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
429 jsonReq, err := m.Marshal(req)
430 if err != nil {
431 return nil, err
432 }
433
434 baseUrl, err := url.Parse(c.endpoint)
435 if err != nil {
436 return nil, err
437 }
438 baseUrl.Path += fmt.Sprintf("/v2beta/%v:conversationalSearch", req.GetPlacement())
439
440 params := url.Values{}
441 params.Add("$alt", "json;enum-encoding=int")
442
443 baseUrl.RawQuery = params.Encode()
444
445 // Build HTTP headers from client and context metadata.
446 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "placement", url.QueryEscape(req.GetPlacement()))}
447
448 hds = append(c.xGoogHeaders, hds...)
449 hds = append(hds, "Content-Type", "application/json")
450 headers := gax.BuildHeaders(ctx, hds...)
451 var streamClient *conversationalSearchRESTStreamClient
452 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
453 if settings.Path != "" {
454 baseUrl.Path = settings.Path
455 }
456 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
457 if err != nil {
458 return err
459 }
460 httpReq = httpReq.WithContext(ctx)
461 httpReq.Header = headers
462
463 httpRsp, err := executeStreamingHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ConversationalSearch")
464 if err != nil {
465 return err
466 }
467
468 streamClient = &conversationalSearchRESTStreamClient{
469 ctx: ctx,
470 md: metadata.MD(httpRsp.Header),
471 stream: gax.NewProtoJSONStreamReader(httpRsp.Body, (&retailpb.ConversationalSearchResponse{}).ProtoReflect().Type()),
472 }
473 return nil
474 }, opts...)
475
476 return streamClient, e
477 }
478
479 // conversationalSearchRESTStreamClient is the stream client used to consume the server stream created by
480 // the REST implementation of ConversationalSearch.
481 type conversationalSearchRESTStreamClient struct {
482 ctx context.Context
483 md metadata.MD
484 stream *gax.ProtoJSONStream
485 }
486
487 func (c *conversationalSearchRESTStreamClient) Recv() (*retailpb.ConversationalSearchResponse, error) {
488 if err := c.ctx.Err(); err != nil {
489 defer c.stream.Close()
490 return nil, err
491 }
492 msg, err := c.stream.Recv()
493 if err != nil {
494 defer c.stream.Close()
495 return nil, err
496 }
497 res := msg.(*retailpb.ConversationalSearchResponse)
498 return res, nil
499 }
500
501 func (c *conversationalSearchRESTStreamClient) Header() (metadata.MD, error) {
502 return c.md, nil
503 }
504
505 func (c *conversationalSearchRESTStreamClient) Trailer() metadata.MD {
506 return c.md
507 }
508
509 func (c *conversationalSearchRESTStreamClient) CloseSend() error {
510 // This is a no-op to fulfill the interface.
511 return errors.New("this method is not implemented for a server-stream")
512 }
513
514 func (c *conversationalSearchRESTStreamClient) Context() context.Context {
515 return c.ctx
516 }
517
518 func (c *conversationalSearchRESTStreamClient) SendMsg(m interface{}) error {
519 // This is a no-op to fulfill the interface.
520 return errors.New("this method is not implemented for a server-stream")
521 }
522
523 func (c *conversationalSearchRESTStreamClient) RecvMsg(m interface{}) error {
524 // This is a no-op to fulfill the interface.
525 return errors.New("this method is not implemented, use Recv")
526 }
527
528 // GetOperation is a utility method from google.longrunning.Operations.
529 func (c *conversationalSearchRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
530 baseUrl, err := url.Parse(c.endpoint)
531 if err != nil {
532 return nil, err
533 }
534 baseUrl.Path += fmt.Sprintf("/v2beta/%v", req.GetName())
535
536 params := url.Values{}
537 params.Add("$alt", "json;enum-encoding=int")
538
539 baseUrl.RawQuery = params.Encode()
540
541 // Build HTTP headers from client and context metadata.
542 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
543
544 hds = append(c.xGoogHeaders, hds...)
545 hds = append(hds, "Content-Type", "application/json")
546 headers := gax.BuildHeaders(ctx, hds...)
547 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
548 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
549 resp := &longrunningpb.Operation{}
550 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
551 if settings.Path != "" {
552 baseUrl.Path = settings.Path
553 }
554 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
555 if err != nil {
556 return err
557 }
558 httpReq = httpReq.WithContext(ctx)
559 httpReq.Header = headers
560
561 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
562 if err != nil {
563 return err
564 }
565
566 if err := unm.Unmarshal(buf, resp); err != nil {
567 return err
568 }
569
570 return nil
571 }, opts...)
572 if e != nil {
573 return nil, e
574 }
575 return resp, nil
576 }
577
578 // ListOperations is a utility method from google.longrunning.Operations.
579 func (c *conversationalSearchRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
580 it := &OperationIterator{}
581 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
582 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
583 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
584 resp := &longrunningpb.ListOperationsResponse{}
585 if pageToken != "" {
586 req.PageToken = pageToken
587 }
588 if pageSize > math.MaxInt32 {
589 req.PageSize = math.MaxInt32
590 } else if pageSize != 0 {
591 req.PageSize = int32(pageSize)
592 }
593 baseUrl, err := url.Parse(c.endpoint)
594 if err != nil {
595 return nil, "", err
596 }
597 baseUrl.Path += fmt.Sprintf("/v2beta/%v/operations", req.GetName())
598
599 params := url.Values{}
600 params.Add("$alt", "json;enum-encoding=int")
601 if req.GetFilter() != "" {
602 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
603 }
604 if req.GetPageSize() != 0 {
605 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
606 }
607 if req.GetPageToken() != "" {
608 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
609 }
610
611 baseUrl.RawQuery = params.Encode()
612
613 // Build HTTP headers from client and context metadata.
614 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
615 headers := gax.BuildHeaders(ctx, hds...)
616 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
617 if settings.Path != "" {
618 baseUrl.Path = settings.Path
619 }
620 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
621 if err != nil {
622 return err
623 }
624 httpReq.Header = headers
625
626 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
627 if err != nil {
628 return err
629 }
630 if err := unm.Unmarshal(buf, resp); err != nil {
631 return err
632 }
633
634 return nil
635 }, opts...)
636 if e != nil {
637 return nil, "", e
638 }
639 it.Response = resp
640 return resp.GetOperations(), resp.GetNextPageToken(), nil
641 }
642
643 fetch := func(pageSize int, pageToken string) (string, error) {
644 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
645 if err != nil {
646 return "", err
647 }
648 it.items = append(it.items, items...)
649 return nextPageToken, nil
650 }
651
652 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
653 it.pageInfo.MaxSize = int(req.GetPageSize())
654 it.pageInfo.Token = req.GetPageToken()
655
656 return it
657 }