Debian Codegraph @

locationfinder/apiv1/cloud_location_finder_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 locationfinder
18
19 import (
20 "context"
21 "fmt"
22 "log/slog"
23 "math"
24 "net/http"
25 "net/url"
26 "time"
27
28 locationfinderpb "cloud.google.com/go/locationfinder/apiv1/locationfinderpb"
29 gax "github.com/googleapis/gax-go/v2"
30 "google.golang.org/api/iterator"
31 "google.golang.org/api/option"
32 "google.golang.org/api/option/internaloption"
33 gtransport "google.golang.org/api/transport/grpc"
34 httptransport "google.golang.org/api/transport/http"
35 locationpb "google.golang.org/genproto/googleapis/cloud/location"
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 newCloudLocationFinderClientHook clientHook
43
44 // CloudLocationFinderCallOptions contains the retry settings for each method of CloudLocationFinderClient.
45 type CloudLocationFinderCallOptions struct {
46 ListCloudLocations []gax.CallOption
47 GetCloudLocation []gax.CallOption
48 SearchCloudLocations []gax.CallOption
49 GetLocation []gax.CallOption
50 ListLocations []gax.CallOption
51 }
52
53 func defaultCloudLocationFinderGRPCClientOptions() []option.ClientOption {
54 return []option.ClientOption{
55 internaloption.WithDefaultEndpoint("cloudlocationfinder.googleapis.com:443"),
56 internaloption.WithDefaultEndpointTemplate("cloudlocationfinder.UNIVERSE_DOMAIN:443"),
57 internaloption.WithDefaultMTLSEndpoint("cloudlocationfinder.mtls.googleapis.com:443"),
58 internaloption.WithDefaultUniverseDomain("googleapis.com"),
59 internaloption.WithDefaultAudience("https://cloudlocationfinder.googleapis.com/"),
60 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
61 internaloption.EnableJwtWithScope(),
62 internaloption.EnableNewAuthLibrary(),
63 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
64 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
65 }
66 }
67
68 func defaultCloudLocationFinderCallOptions() *CloudLocationFinderCallOptions {
69 return &CloudLocationFinderCallOptions{
70 ListCloudLocations: []gax.CallOption{
71 gax.WithTimeout(60000 * time.Millisecond),
72 gax.WithRetry(func() gax.Retryer {
73 return gax.OnCodes([]codes.Code{
74 codes.Unavailable,
75 }, gax.Backoff{
76 Initial: 1000 * time.Millisecond,
77 Max: 10000 * time.Millisecond,
78 Multiplier: 1.30,
79 })
80 }),
81 },
82 GetCloudLocation: []gax.CallOption{
83 gax.WithTimeout(60000 * time.Millisecond),
84 gax.WithRetry(func() gax.Retryer {
85 return gax.OnCodes([]codes.Code{
86 codes.Unavailable,
87 }, gax.Backoff{
88 Initial: 1000 * time.Millisecond,
89 Max: 10000 * time.Millisecond,
90 Multiplier: 1.30,
91 })
92 }),
93 },
94 SearchCloudLocations: []gax.CallOption{
95 gax.WithTimeout(60000 * time.Millisecond),
96 gax.WithRetry(func() gax.Retryer {
97 return gax.OnCodes([]codes.Code{
98 codes.Unavailable,
99 }, gax.Backoff{
100 Initial: 1000 * time.Millisecond,
101 Max: 10000 * time.Millisecond,
102 Multiplier: 1.30,
103 })
104 }),
105 },
106 GetLocation: []gax.CallOption{},
107 ListLocations: []gax.CallOption{},
108 }
109 }
110
111 func defaultCloudLocationFinderRESTCallOptions() *CloudLocationFinderCallOptions {
112 return &CloudLocationFinderCallOptions{
113 ListCloudLocations: []gax.CallOption{
114 gax.WithTimeout(60000 * time.Millisecond),
115 gax.WithRetry(func() gax.Retryer {
116 return gax.OnHTTPCodes(gax.Backoff{
117 Initial: 1000 * time.Millisecond,
118 Max: 10000 * time.Millisecond,
119 Multiplier: 1.30,
120 },
121 http.StatusServiceUnavailable)
122 }),
123 },
124 GetCloudLocation: []gax.CallOption{
125 gax.WithTimeout(60000 * time.Millisecond),
126 gax.WithRetry(func() gax.Retryer {
127 return gax.OnHTTPCodes(gax.Backoff{
128 Initial: 1000 * time.Millisecond,
129 Max: 10000 * time.Millisecond,
130 Multiplier: 1.30,
131 },
132 http.StatusServiceUnavailable)
133 }),
134 },
135 SearchCloudLocations: []gax.CallOption{
136 gax.WithTimeout(60000 * time.Millisecond),
137 gax.WithRetry(func() gax.Retryer {
138 return gax.OnHTTPCodes(gax.Backoff{
139 Initial: 1000 * time.Millisecond,
140 Max: 10000 * time.Millisecond,
141 Multiplier: 1.30,
142 },
143 http.StatusServiceUnavailable)
144 }),
145 },
146 GetLocation: []gax.CallOption{},
147 ListLocations: []gax.CallOption{},
148 }
149 }
150
151 // internalCloudLocationFinderClient is an interface that defines the methods available from Cloud Location Finder API.
152 type internalCloudLocationFinderClient interface {
153 Close() error
154 setGoogleClientInfo(...string)
155 Connection() *grpc.ClientConn
156 ListCloudLocations(context.Context, *locationfinderpb.ListCloudLocationsRequest, ...gax.CallOption) *CloudLocationIterator
157 GetCloudLocation(context.Context, *locationfinderpb.GetCloudLocationRequest, ...gax.CallOption) (*locationfinderpb.CloudLocation, error)
158 SearchCloudLocations(context.Context, *locationfinderpb.SearchCloudLocationsRequest, ...gax.CallOption) *CloudLocationIterator
159 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
160 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
161 }
162
163 // CloudLocationFinderClient is a client for interacting with Cloud Location Finder API.
164 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
165 //
166 // Service describing handlers for resources
167 type CloudLocationFinderClient struct {
168 // The internal transport-dependent client.
169 internalClient internalCloudLocationFinderClient
170
171 // The call options for this service.
172 CallOptions *CloudLocationFinderCallOptions
173 }
174
175 // Wrapper methods routed to the internal client.
176
177 // Close closes the connection to the API service. The user should invoke this when
178 // the client is no longer required.
179 func (c *CloudLocationFinderClient) Close() error {
180 return c.internalClient.Close()
181 }
182
183 // setGoogleClientInfo sets the name and version of the application in
184 // the `x-goog-api-client` header passed on each request. Intended for
185 // use by Google-written clients.
186 func (c *CloudLocationFinderClient) setGoogleClientInfo(keyval ...string) {
187 c.internalClient.setGoogleClientInfo(keyval...)
188 }
189
190 // Connection returns a connection to the API service.
191 //
192 // Deprecated: Connections are now pooled so this method does not always
193 // return the same resource.
194 func (c *CloudLocationFinderClient) Connection() *grpc.ClientConn {
195 return c.internalClient.Connection()
196 }
197
198 // ListCloudLocations lists cloud locations under a given project and location.
199 func (c *CloudLocationFinderClient) ListCloudLocations(ctx context.Context, req *locationfinderpb.ListCloudLocationsRequest, opts ...gax.CallOption) *CloudLocationIterator {
200 return c.internalClient.ListCloudLocations(ctx, req, opts...)
201 }
202
203 // GetCloudLocation retrieves a resource containing information about a cloud location.
204 func (c *CloudLocationFinderClient) GetCloudLocation(ctx context.Context, req *locationfinderpb.GetCloudLocationRequest, opts ...gax.CallOption) (*locationfinderpb.CloudLocation, error) {
205 return c.internalClient.GetCloudLocation(ctx, req, opts...)
206 }
207
208 // SearchCloudLocations searches for cloud locations from a given source location.
209 func (c *CloudLocationFinderClient) SearchCloudLocations(ctx context.Context, req *locationfinderpb.SearchCloudLocationsRequest, opts ...gax.CallOption) *CloudLocationIterator {
210 return c.internalClient.SearchCloudLocations(ctx, req, opts...)
211 }
212
213 // GetLocation gets information about a location.
214 func (c *CloudLocationFinderClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
215 return c.internalClient.GetLocation(ctx, req, opts...)
216 }
217
218 // ListLocations lists information about the supported locations for this service.
219 func (c *CloudLocationFinderClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
220 return c.internalClient.ListLocations(ctx, req, opts...)
221 }
222
223 // cloudLocationFinderGRPCClient is a client for interacting with Cloud Location Finder API over gRPC transport.
224 //
225 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
226 type cloudLocationFinderGRPCClient struct {
227 // Connection pool of gRPC connections to the service.
228 connPool gtransport.ConnPool
229
230 // Points back to the CallOptions field of the containing CloudLocationFinderClient
231 CallOptions **CloudLocationFinderCallOptions
232
233 // The gRPC API client.
234 cloudLocationFinderClient locationfinderpb.CloudLocationFinderClient
235
236 locationsClient locationpb.LocationsClient
237
238 // The x-goog-* metadata to be sent with each request.
239 xGoogHeaders []string
240
241 logger *slog.Logger
242 }
243
244 // NewCloudLocationFinderClient creates a new cloud location finder client based on gRPC.
245 // The returned client must be Closed when it is done being used to clean up its underlying connections.
246 //
247 // Service describing handlers for resources
248 func NewCloudLocationFinderClient(ctx context.Context, opts ...option.ClientOption) (*CloudLocationFinderClient, error) {
249 clientOpts := defaultCloudLocationFinderGRPCClientOptions()
250 if newCloudLocationFinderClientHook != nil {
251 hookOpts, err := newCloudLocationFinderClientHook(ctx, clientHookParams{})
252 if err != nil {
253 return nil, err
254 }
255 clientOpts = append(clientOpts, hookOpts...)
256 }
257
258 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
259 if err != nil {
260 return nil, err
261 }
262 client := CloudLocationFinderClient{CallOptions: defaultCloudLocationFinderCallOptions()}
263
264 c := &cloudLocationFinderGRPCClient{
265 connPool: connPool,
266 cloudLocationFinderClient: locationfinderpb.NewCloudLocationFinderClient(connPool),
267 CallOptions: &client.CallOptions,
268 logger: internaloption.GetLogger(opts),
269 locationsClient: locationpb.NewLocationsClient(connPool),
270 }
271 c.setGoogleClientInfo()
272
273 client.internalClient = c
274
275 return &client, nil
276 }
277
278 // Connection returns a connection to the API service.
279 //
280 // Deprecated: Connections are now pooled so this method does not always
281 // return the same resource.
282 func (c *cloudLocationFinderGRPCClient) Connection() *grpc.ClientConn {
283 return c.connPool.Conn()
284 }
285
286 // setGoogleClientInfo sets the name and version of the application in
287 // the `x-goog-api-client` header passed on each request. Intended for
288 // use by Google-written clients.
289 func (c *cloudLocationFinderGRPCClient) setGoogleClientInfo(keyval ...string) {
290 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
291 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
292 c.xGoogHeaders = []string{
293 "x-goog-api-client", gax.XGoogHeader(kv...),
294 }
295 }
296
297 // Close closes the connection to the API service. The user should invoke this when
298 // the client is no longer required.
299 func (c *cloudLocationFinderGRPCClient) Close() error {
300 return c.connPool.Close()
301 }
302
303 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
304 type cloudLocationFinderRESTClient struct {
305 // The http endpoint to connect to.
306 endpoint string
307
308 // The http client.
309 httpClient *http.Client
310
311 // The x-goog-* headers to be sent with each request.
312 xGoogHeaders []string
313
314 // Points back to the CallOptions field of the containing CloudLocationFinderClient
315 CallOptions **CloudLocationFinderCallOptions
316
317 logger *slog.Logger
318 }
319
320 // NewCloudLocationFinderRESTClient creates a new cloud location finder rest client.
321 //
322 // Service describing handlers for resources
323 func NewCloudLocationFinderRESTClient(ctx context.Context, opts ...option.ClientOption) (*CloudLocationFinderClient, error) {
324 clientOpts := append(defaultCloudLocationFinderRESTClientOptions(), opts...)
325 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
326 if err != nil {
327 return nil, err
328 }
329
330 callOpts := defaultCloudLocationFinderRESTCallOptions()
331 c := &cloudLocationFinderRESTClient{
332 endpoint: endpoint,
333 httpClient: httpClient,
334 CallOptions: &callOpts,
335 logger: internaloption.GetLogger(opts),
336 }
337 c.setGoogleClientInfo()
338
339 return &CloudLocationFinderClient{internalClient: c, CallOptions: callOpts}, nil
340 }
341
342 func defaultCloudLocationFinderRESTClientOptions() []option.ClientOption {
343 return []option.ClientOption{
344 internaloption.WithDefaultEndpoint("https://cloudlocationfinder.googleapis.com"),
345 internaloption.WithDefaultEndpointTemplate("https://cloudlocationfinder.UNIVERSE_DOMAIN"),
346 internaloption.WithDefaultMTLSEndpoint("https://cloudlocationfinder.mtls.googleapis.com"),
347 internaloption.WithDefaultUniverseDomain("googleapis.com"),
348 internaloption.WithDefaultAudience("https://cloudlocationfinder.googleapis.com/"),
349 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
350 internaloption.EnableNewAuthLibrary(),
351 }
352 }
353
354 // setGoogleClientInfo sets the name and version of the application in
355 // the `x-goog-api-client` header passed on each request. Intended for
356 // use by Google-written clients.
357 func (c *cloudLocationFinderRESTClient) setGoogleClientInfo(keyval ...string) {
358 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
359 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
360 c.xGoogHeaders = []string{
361 "x-goog-api-client", gax.XGoogHeader(kv...),
362 }
363 }
364
365 // Close closes the connection to the API service. The user should invoke this when
366 // the client is no longer required.
367 func (c *cloudLocationFinderRESTClient) Close() error {
368 // Replace httpClient with nil to force cleanup.
369 c.httpClient = nil
370 return nil
371 }
372
373 // Connection returns a connection to the API service.
374 //
375 // Deprecated: This method always returns nil.
376 func (c *cloudLocationFinderRESTClient) Connection() *grpc.ClientConn {
377 return nil
378 }
379 func (c *cloudLocationFinderGRPCClient) ListCloudLocations(ctx context.Context, req *locationfinderpb.ListCloudLocationsRequest, opts ...gax.CallOption) *CloudLocationIterator {
380 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
381
382 hds = append(c.xGoogHeaders, hds...)
383 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
384 opts = append((*c.CallOptions).ListCloudLocations[0:len((*c.CallOptions).ListCloudLocations):len((*c.CallOptions).ListCloudLocations)], opts...)
385 it := &CloudLocationIterator{}
386 req = proto.Clone(req).(*locationfinderpb.ListCloudLocationsRequest)
387 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationfinderpb.CloudLocation, string, error) {
388 resp := &locationfinderpb.ListCloudLocationsResponse{}
389 if pageToken != "" {
390 req.PageToken = pageToken
391 }
392 if pageSize > math.MaxInt32 {
393 req.PageSize = math.MaxInt32
394 } else if pageSize != 0 {
395 req.PageSize = int32(pageSize)
396 }
397 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
398 var err error
399 resp, err = executeRPC(ctx, c.cloudLocationFinderClient.ListCloudLocations, req, settings.GRPC, c.logger, "ListCloudLocations")
400 return err
401 }, opts...)
402 if err != nil {
403 return nil, "", err
404 }
405
406 it.Response = resp
407 return resp.GetCloudLocations(), resp.GetNextPageToken(), nil
408 }
409 fetch := func(pageSize int, pageToken string) (string, error) {
410 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
411 if err != nil {
412 return "", err
413 }
414 it.items = append(it.items, items...)
415 return nextPageToken, nil
416 }
417
418 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
419 it.pageInfo.MaxSize = int(req.GetPageSize())
420 it.pageInfo.Token = req.GetPageToken()
421
422 return it
423 }
424
425 func (c *cloudLocationFinderGRPCClient) GetCloudLocation(ctx context.Context, req *locationfinderpb.GetCloudLocationRequest, opts ...gax.CallOption) (*locationfinderpb.CloudLocation, error) {
426 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
427
428 hds = append(c.xGoogHeaders, hds...)
429 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
430 opts = append((*c.CallOptions).GetCloudLocation[0:len((*c.CallOptions).GetCloudLocation):len((*c.CallOptions).GetCloudLocation)], opts...)
431 var resp *locationfinderpb.CloudLocation
432 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
433 var err error
434 resp, err = executeRPC(ctx, c.cloudLocationFinderClient.GetCloudLocation, req, settings.GRPC, c.logger, "GetCloudLocation")
435 return err
436 }, opts...)
437 if err != nil {
438 return nil, err
439 }
440 return resp, nil
441 }
442
443 func (c *cloudLocationFinderGRPCClient) SearchCloudLocations(ctx context.Context, req *locationfinderpb.SearchCloudLocationsRequest, opts ...gax.CallOption) *CloudLocationIterator {
444 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
445
446 hds = append(c.xGoogHeaders, hds...)
447 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
448 opts = append((*c.CallOptions).SearchCloudLocations[0:len((*c.CallOptions).SearchCloudLocations):len((*c.CallOptions).SearchCloudLocations)], opts...)
449 it := &CloudLocationIterator{}
450 req = proto.Clone(req).(*locationfinderpb.SearchCloudLocationsRequest)
451 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationfinderpb.CloudLocation, string, error) {
452 resp := &locationfinderpb.SearchCloudLocationsResponse{}
453 if pageToken != "" {
454 req.PageToken = pageToken
455 }
456 if pageSize > math.MaxInt32 {
457 req.PageSize = math.MaxInt32
458 } else if pageSize != 0 {
459 req.PageSize = int32(pageSize)
460 }
461 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
462 var err error
463 resp, err = executeRPC(ctx, c.cloudLocationFinderClient.SearchCloudLocations, req, settings.GRPC, c.logger, "SearchCloudLocations")
464 return err
465 }, opts...)
466 if err != nil {
467 return nil, "", err
468 }
469
470 it.Response = resp
471 return resp.GetCloudLocations(), resp.GetNextPageToken(), nil
472 }
473 fetch := func(pageSize int, pageToken string) (string, error) {
474 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
475 if err != nil {
476 return "", err
477 }
478 it.items = append(it.items, items...)
479 return nextPageToken, nil
480 }
481
482 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
483 it.pageInfo.MaxSize = int(req.GetPageSize())
484 it.pageInfo.Token = req.GetPageToken()
485
486 return it
487 }
488
489 func (c *cloudLocationFinderGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
490 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
491
492 hds = append(c.xGoogHeaders, hds...)
493 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
494 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
495 var resp *locationpb.Location
496 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
497 var err error
498 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
499 return err
500 }, opts...)
501 if err != nil {
502 return nil, err
503 }
504 return resp, nil
505 }
506
507 func (c *cloudLocationFinderGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
508 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
509
510 hds = append(c.xGoogHeaders, hds...)
511 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
512 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
513 it := &LocationIterator{}
514 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
515 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
516 resp := &locationpb.ListLocationsResponse{}
517 if pageToken != "" {
518 req.PageToken = pageToken
519 }
520 if pageSize > math.MaxInt32 {
521 req.PageSize = math.MaxInt32
522 } else if pageSize != 0 {
523 req.PageSize = int32(pageSize)
524 }
525 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
526 var err error
527 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
528 return err
529 }, opts...)
530 if err != nil {
531 return nil, "", err
532 }
533
534 it.Response = resp
535 return resp.GetLocations(), resp.GetNextPageToken(), nil
536 }
537 fetch := func(pageSize int, pageToken string) (string, error) {
538 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
539 if err != nil {
540 return "", err
541 }
542 it.items = append(it.items, items...)
543 return nextPageToken, nil
544 }
545
546 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
547 it.pageInfo.MaxSize = int(req.GetPageSize())
548 it.pageInfo.Token = req.GetPageToken()
549
550 return it
551 }
552
553 // ListCloudLocations lists cloud locations under a given project and location.
554 func (c *cloudLocationFinderRESTClient) ListCloudLocations(ctx context.Context, req *locationfinderpb.ListCloudLocationsRequest, opts ...gax.CallOption) *CloudLocationIterator {
555 it := &CloudLocationIterator{}
556 req = proto.Clone(req).(*locationfinderpb.ListCloudLocationsRequest)
557 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
558 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationfinderpb.CloudLocation, string, error) {
559 resp := &locationfinderpb.ListCloudLocationsResponse{}
560 if pageToken != "" {
561 req.PageToken = pageToken
562 }
563 if pageSize > math.MaxInt32 {
564 req.PageSize = math.MaxInt32
565 } else if pageSize != 0 {
566 req.PageSize = int32(pageSize)
567 }
568 baseUrl, err := url.Parse(c.endpoint)
569 if err != nil {
570 return nil, "", err
571 }
572 baseUrl.Path += fmt.Sprintf("/v1/%v/cloudLocations", req.GetParent())
573
574 params := url.Values{}
575 params.Add("$alt", "json;enum-encoding=int")
576 if req.GetFilter() != "" {
577 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
578 }
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, "ListCloudLocations")
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.GetCloudLocations(), 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 }
633
634 // GetCloudLocation retrieves a resource containing information about a cloud location.
635 func (c *cloudLocationFinderRESTClient) GetCloudLocation(ctx context.Context, req *locationfinderpb.GetCloudLocationRequest, opts ...gax.CallOption) (*locationfinderpb.CloudLocation, error) {
636 baseUrl, err := url.Parse(c.endpoint)
637 if err != nil {
638 return nil, err
639 }
640 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
641
642 params := url.Values{}
643 params.Add("$alt", "json;enum-encoding=int")
644
645 baseUrl.RawQuery = params.Encode()
646
647 // Build HTTP headers from client and context metadata.
648 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
649
650 hds = append(c.xGoogHeaders, hds...)
651 hds = append(hds, "Content-Type", "application/json")
652 headers := gax.BuildHeaders(ctx, hds...)
653 opts = append((*c.CallOptions).GetCloudLocation[0:len((*c.CallOptions).GetCloudLocation):len((*c.CallOptions).GetCloudLocation)], opts...)
654 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
655 resp := &locationfinderpb.CloudLocation{}
656 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
657 if settings.Path != "" {
658 baseUrl.Path = settings.Path
659 }
660 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
661 if err != nil {
662 return err
663 }
664 httpReq = httpReq.WithContext(ctx)
665 httpReq.Header = headers
666
667 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCloudLocation")
668 if err != nil {
669 return err
670 }
671
672 if err := unm.Unmarshal(buf, resp); err != nil {
673 return err
674 }
675
676 return nil
677 }, opts...)
678 if e != nil {
679 return nil, e
680 }
681 return resp, nil
682 }
683
684 // SearchCloudLocations searches for cloud locations from a given source location.
685 func (c *cloudLocationFinderRESTClient) SearchCloudLocations(ctx context.Context, req *locationfinderpb.SearchCloudLocationsRequest, opts ...gax.CallOption) *CloudLocationIterator {
686 it := &CloudLocationIterator{}
687 req = proto.Clone(req).(*locationfinderpb.SearchCloudLocationsRequest)
688 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
689 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationfinderpb.CloudLocation, string, error) {
690 resp := &locationfinderpb.SearchCloudLocationsResponse{}
691 if pageToken != "" {
692 req.PageToken = pageToken
693 }
694 if pageSize > math.MaxInt32 {
695 req.PageSize = math.MaxInt32
696 } else if pageSize != 0 {
697 req.PageSize = int32(pageSize)
698 }
699 baseUrl, err := url.Parse(c.endpoint)
700 if err != nil {
701 return nil, "", err
702 }
703 baseUrl.Path += fmt.Sprintf("/v1/%v/cloudLocations:search", req.GetParent())
704
705 params := url.Values{}
706 params.Add("$alt", "json;enum-encoding=int")
707 if req.GetPageSize() != 0 {
708 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
709 }
710 if req.GetPageToken() != "" {
711 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
712 }
713 if req.GetQuery() != "" {
714 params.Add("query", fmt.Sprintf("%v", req.GetQuery()))
715 }
716 params.Add("sourceCloudLocation", fmt.Sprintf("%v", req.GetSourceCloudLocation()))
717
718 baseUrl.RawQuery = params.Encode()
719
720 // Build HTTP headers from client and context metadata.
721 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
722 headers := gax.BuildHeaders(ctx, hds...)
723 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
724 if settings.Path != "" {
725 baseUrl.Path = settings.Path
726 }
727 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
728 if err != nil {
729 return err
730 }
731 httpReq.Header = headers
732
733 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "SearchCloudLocations")
734 if err != nil {
735 return err
736 }
737 if err := unm.Unmarshal(buf, resp); err != nil {
738 return err
739 }
740
741 return nil
742 }, opts...)
743 if e != nil {
744 return nil, "", e
745 }
746 it.Response = resp
747 return resp.GetCloudLocations(), resp.GetNextPageToken(), nil
748 }
749
750 fetch := func(pageSize int, pageToken string) (string, error) {
751 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
752 if err != nil {
753 return "", err
754 }
755 it.items = append(it.items, items...)
756 return nextPageToken, nil
757 }
758
759 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
760 it.pageInfo.MaxSize = int(req.GetPageSize())
761 it.pageInfo.Token = req.GetPageToken()
762
763 return it
764 }
765
766 // GetLocation gets information about a location.
767 func (c *cloudLocationFinderRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
768 baseUrl, err := url.Parse(c.endpoint)
769 if err != nil {
770 return nil, err
771 }
772 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
773
774 params := url.Values{}
775 params.Add("$alt", "json;enum-encoding=int")
776
777 baseUrl.RawQuery = params.Encode()
778
779 // Build HTTP headers from client and context metadata.
780 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
781
782 hds = append(c.xGoogHeaders, hds...)
783 hds = append(hds, "Content-Type", "application/json")
784 headers := gax.BuildHeaders(ctx, hds...)
785 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
786 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
787 resp := &locationpb.Location{}
788 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
789 if settings.Path != "" {
790 baseUrl.Path = settings.Path
791 }
792 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
793 if err != nil {
794 return err
795 }
796 httpReq = httpReq.WithContext(ctx)
797 httpReq.Header = headers
798
799 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
800 if err != nil {
801 return err
802 }
803
804 if err := unm.Unmarshal(buf, resp); err != nil {
805 return err
806 }
807
808 return nil
809 }, opts...)
810 if e != nil {
811 return nil, e
812 }
813 return resp, nil
814 }
815
816 // ListLocations lists information about the supported locations for this service.
817 func (c *cloudLocationFinderRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
818 it := &LocationIterator{}
819 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
820 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
821 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
822 resp := &locationpb.ListLocationsResponse{}
823 if pageToken != "" {
824 req.PageToken = pageToken
825 }
826 if pageSize > math.MaxInt32 {
827 req.PageSize = math.MaxInt32
828 } else if pageSize != 0 {
829 req.PageSize = int32(pageSize)
830 }
831 baseUrl, err := url.Parse(c.endpoint)
832 if err != nil {
833 return nil, "", err
834 }
835 baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName())
836
837 params := url.Values{}
838 params.Add("$alt", "json;enum-encoding=int")
839 if req.GetFilter() != "" {
840 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
841 }
842 if req.GetPageSize() != 0 {
843 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
844 }
845 if req.GetPageToken() != "" {
846 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
847 }
848
849 baseUrl.RawQuery = params.Encode()
850
851 // Build HTTP headers from client and context metadata.
852 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
853 headers := gax.BuildHeaders(ctx, hds...)
854 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
855 if settings.Path != "" {
856 baseUrl.Path = settings.Path
857 }
858 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
859 if err != nil {
860 return err
861 }
862 httpReq.Header = headers
863
864 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
865 if err != nil {
866 return err
867 }
868 if err := unm.Unmarshal(buf, resp); err != nil {
869 return err
870 }
871
872 return nil
873 }, opts...)
874 if e != nil {
875 return nil, "", e
876 }
877 it.Response = resp
878 return resp.GetLocations(), resp.GetNextPageToken(), nil
879 }
880
881 fetch := func(pageSize int, pageToken string) (string, error) {
882 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
883 if err != nil {
884 return "", err
885 }
886 it.items = append(it.items, items...)
887 return nextPageToken, nil
888 }
889
890 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
891 it.pageInfo.MaxSize = int(req.GetPageSize())
892 it.pageInfo.Token = req.GetPageToken()
893
894 return it
895 }