Debian Codegraph @

shopping/merchant/accounts/apiv1/account_relationships_client.go

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