Debian Codegraph @

apihub/apiv1/api_hub_discovery_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 apihub
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27
28 apihubpb "cloud.google.com/go/apihub/apiv1/apihubpb"
29 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
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 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/protobuf/encoding/protojson"
38 "google.golang.org/protobuf/proto"
39 )
40
41 var newApiHubDiscoveryClientHook clientHook
42
43 // ApiHubDiscoveryCallOptions contains the retry settings for each method of ApiHubDiscoveryClient.
44 type ApiHubDiscoveryCallOptions struct {
45 ListDiscoveredApiObservations []gax.CallOption
46 GetDiscoveredApiObservation []gax.CallOption
47 ListDiscoveredApiOperations []gax.CallOption
48 GetDiscoveredApiOperation []gax.CallOption
49 GetLocation []gax.CallOption
50 ListLocations []gax.CallOption
51 CancelOperation []gax.CallOption
52 DeleteOperation []gax.CallOption
53 GetOperation []gax.CallOption
54 ListOperations []gax.CallOption
55 }
56
57 func defaultApiHubDiscoveryRESTCallOptions() *ApiHubDiscoveryCallOptions {
58 return &ApiHubDiscoveryCallOptions{
59 ListDiscoveredApiObservations: []gax.CallOption{},
60 GetDiscoveredApiObservation: []gax.CallOption{},
61 ListDiscoveredApiOperations: []gax.CallOption{},
62 GetDiscoveredApiOperation: []gax.CallOption{},
63 GetLocation: []gax.CallOption{},
64 ListLocations: []gax.CallOption{},
65 CancelOperation: []gax.CallOption{},
66 DeleteOperation: []gax.CallOption{},
67 GetOperation: []gax.CallOption{},
68 ListOperations: []gax.CallOption{},
69 }
70 }
71
72 // internalApiHubDiscoveryClient is an interface that defines the methods available from API hub API.
73 type internalApiHubDiscoveryClient interface {
74 Close() error
75 setGoogleClientInfo(...string)
76 Connection() *grpc.ClientConn
77 ListDiscoveredApiObservations(context.Context, *apihubpb.ListDiscoveredApiObservationsRequest, ...gax.CallOption) *DiscoveredApiObservationIterator
78 GetDiscoveredApiObservation(context.Context, *apihubpb.GetDiscoveredApiObservationRequest, ...gax.CallOption) (*apihubpb.DiscoveredApiObservation, error)
79 ListDiscoveredApiOperations(context.Context, *apihubpb.ListDiscoveredApiOperationsRequest, ...gax.CallOption) *DiscoveredApiOperationIterator
80 GetDiscoveredApiOperation(context.Context, *apihubpb.GetDiscoveredApiOperationRequest, ...gax.CallOption) (*apihubpb.DiscoveredApiOperation, error)
81 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
82 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
83 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
84 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
85 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
86 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
87 }
88
89 // ApiHubDiscoveryClient is a client for interacting with API hub API.
90 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
91 //
92 // This service exposes methods used to manage DiscoveredApiObservations
93 // and DiscoveredApiOperations.
94 type ApiHubDiscoveryClient struct {
95 // The internal transport-dependent client.
96 internalClient internalApiHubDiscoveryClient
97
98 // The call options for this service.
99 CallOptions *ApiHubDiscoveryCallOptions
100 }
101
102 // Wrapper methods routed to the internal client.
103
104 // Close closes the connection to the API service. The user should invoke this when
105 // the client is no longer required.
106 func (c *ApiHubDiscoveryClient) Close() error {
107 return c.internalClient.Close()
108 }
109
110 // setGoogleClientInfo sets the name and version of the application in
111 // the `x-goog-api-client` header passed on each request. Intended for
112 // use by Google-written clients.
113 func (c *ApiHubDiscoveryClient) setGoogleClientInfo(keyval ...string) {
114 c.internalClient.setGoogleClientInfo(keyval...)
115 }
116
117 // Connection returns a connection to the API service.
118 //
119 // Deprecated: Connections are now pooled so this method does not always
120 // return the same resource.
121 func (c *ApiHubDiscoveryClient) Connection() *grpc.ClientConn {
122 return c.internalClient.Connection()
123 }
124
125 // ListDiscoveredApiObservations lists all the DiscoveredAPIObservations in a given project and location.
126 func (c *ApiHubDiscoveryClient) ListDiscoveredApiObservations(ctx context.Context, req *apihubpb.ListDiscoveredApiObservationsRequest, opts ...gax.CallOption) *DiscoveredApiObservationIterator {
127 return c.internalClient.ListDiscoveredApiObservations(ctx, req, opts...)
128 }
129
130 // GetDiscoveredApiObservation gets a DiscoveredAPIObservation in a given project, location and
131 // ApiObservation.
132 func (c *ApiHubDiscoveryClient) GetDiscoveredApiObservation(ctx context.Context, req *apihubpb.GetDiscoveredApiObservationRequest, opts ...gax.CallOption) (*apihubpb.DiscoveredApiObservation, error) {
133 return c.internalClient.GetDiscoveredApiObservation(ctx, req, opts...)
134 }
135
136 // ListDiscoveredApiOperations lists all the DiscoveredAPIOperations in a given project, location and
137 // ApiObservation.
138 func (c *ApiHubDiscoveryClient) ListDiscoveredApiOperations(ctx context.Context, req *apihubpb.ListDiscoveredApiOperationsRequest, opts ...gax.CallOption) *DiscoveredApiOperationIterator {
139 return c.internalClient.ListDiscoveredApiOperations(ctx, req, opts...)
140 }
141
142 // GetDiscoveredApiOperation gets a DiscoveredAPIOperation in a given project, location,
143 // ApiObservation and ApiOperation.
144 func (c *ApiHubDiscoveryClient) GetDiscoveredApiOperation(ctx context.Context, req *apihubpb.GetDiscoveredApiOperationRequest, opts ...gax.CallOption) (*apihubpb.DiscoveredApiOperation, error) {
145 return c.internalClient.GetDiscoveredApiOperation(ctx, req, opts...)
146 }
147
148 // GetLocation gets information about a location.
149 func (c *ApiHubDiscoveryClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
150 return c.internalClient.GetLocation(ctx, req, opts...)
151 }
152
153 // ListLocations lists information about the supported locations for this service.
154 func (c *ApiHubDiscoveryClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
155 return c.internalClient.ListLocations(ctx, req, opts...)
156 }
157
158 // CancelOperation is a utility method from google.longrunning.Operations.
159 func (c *ApiHubDiscoveryClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
160 return c.internalClient.CancelOperation(ctx, req, opts...)
161 }
162
163 // DeleteOperation is a utility method from google.longrunning.Operations.
164 func (c *ApiHubDiscoveryClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
165 return c.internalClient.DeleteOperation(ctx, req, opts...)
166 }
167
168 // GetOperation is a utility method from google.longrunning.Operations.
169 func (c *ApiHubDiscoveryClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
170 return c.internalClient.GetOperation(ctx, req, opts...)
171 }
172
173 // ListOperations is a utility method from google.longrunning.Operations.
174 func (c *ApiHubDiscoveryClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
175 return c.internalClient.ListOperations(ctx, req, opts...)
176 }
177
178 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
179 type apiHubDiscoveryRESTClient struct {
180 // The http endpoint to connect to.
181 endpoint string
182
183 // The http client.
184 httpClient *http.Client
185
186 // The x-goog-* headers to be sent with each request.
187 xGoogHeaders []string
188
189 // Points back to the CallOptions field of the containing ApiHubDiscoveryClient
190 CallOptions **ApiHubDiscoveryCallOptions
191
192 logger *slog.Logger
193 }
194
195 // NewApiHubDiscoveryRESTClient creates a new api hub discovery rest client.
196 //
197 // This service exposes methods used to manage DiscoveredApiObservations
198 // and DiscoveredApiOperations.
199 func NewApiHubDiscoveryRESTClient(ctx context.Context, opts ...option.ClientOption) (*ApiHubDiscoveryClient, error) {
200 clientOpts := append(defaultApiHubDiscoveryRESTClientOptions(), opts...)
201 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
202 if err != nil {
203 return nil, err
204 }
205
206 callOpts := defaultApiHubDiscoveryRESTCallOptions()
207 c := &apiHubDiscoveryRESTClient{
208 endpoint: endpoint,
209 httpClient: httpClient,
210 CallOptions: &callOpts,
211 logger: internaloption.GetLogger(opts),
212 }
213 c.setGoogleClientInfo()
214
215 return &ApiHubDiscoveryClient{internalClient: c, CallOptions: callOpts}, nil
216 }
217
218 func defaultApiHubDiscoveryRESTClientOptions() []option.ClientOption {
219 return []option.ClientOption{
220 internaloption.WithDefaultEndpoint("https://apihub.googleapis.com"),
221 internaloption.WithDefaultEndpointTemplate("https://apihub.UNIVERSE_DOMAIN"),
222 internaloption.WithDefaultMTLSEndpoint("https://apihub.mtls.googleapis.com"),
223 internaloption.WithDefaultUniverseDomain("googleapis.com"),
224 internaloption.WithDefaultAudience("https://apihub.googleapis.com/"),
225 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
226 internaloption.EnableNewAuthLibrary(),
227 }
228 }
229
230 // setGoogleClientInfo sets the name and version of the application in
231 // the `x-goog-api-client` header passed on each request. Intended for
232 // use by Google-written clients.
233 func (c *apiHubDiscoveryRESTClient) setGoogleClientInfo(keyval ...string) {
234 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
235 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
236 c.xGoogHeaders = []string{
237 "x-goog-api-client", gax.XGoogHeader(kv...),
238 }
239 }
240
241 // Close closes the connection to the API service. The user should invoke this when
242 // the client is no longer required.
243 func (c *apiHubDiscoveryRESTClient) Close() error {
244 // Replace httpClient with nil to force cleanup.
245 c.httpClient = nil
246 return nil
247 }
248
249 // Connection returns a connection to the API service.
250 //
251 // Deprecated: This method always returns nil.
252 func (c *apiHubDiscoveryRESTClient) Connection() *grpc.ClientConn {
253 return nil
254 }
255
256 // ListDiscoveredApiObservations lists all the DiscoveredAPIObservations in a given project and location.
257 func (c *apiHubDiscoveryRESTClient) ListDiscoveredApiObservations(ctx context.Context, req *apihubpb.ListDiscoveredApiObservationsRequest, opts ...gax.CallOption) *DiscoveredApiObservationIterator {
258 it := &DiscoveredApiObservationIterator{}
259 req = proto.Clone(req).(*apihubpb.ListDiscoveredApiObservationsRequest)
260 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
261 it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.DiscoveredApiObservation, string, error) {
262 resp := &apihubpb.ListDiscoveredApiObservationsResponse{}
263 if pageToken != "" {
264 req.PageToken = pageToken
265 }
266 if pageSize > math.MaxInt32 {
267 req.PageSize = math.MaxInt32
268 } else if pageSize != 0 {
269 req.PageSize = int32(pageSize)
270 }
271 baseUrl, err := url.Parse(c.endpoint)
272 if err != nil {
273 return nil, "", err
274 }
275 baseUrl.Path += fmt.Sprintf("/v1/%v/discoveredApiObservations", req.GetParent())
276
277 params := url.Values{}
278 params.Add("$alt", "json;enum-encoding=int")
279 if req.GetPageSize() != 0 {
280 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
281 }
282 if req.GetPageToken() != "" {
283 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
284 }
285
286 baseUrl.RawQuery = params.Encode()
287
288 // Build HTTP headers from client and context metadata.
289 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
290 headers := gax.BuildHeaders(ctx, hds...)
291 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
292 if settings.Path != "" {
293 baseUrl.Path = settings.Path
294 }
295 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
296 if err != nil {
297 return err
298 }
299 httpReq.Header = headers
300
301 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDiscoveredApiObservations")
302 if err != nil {
303 return err
304 }
305 if err := unm.Unmarshal(buf, resp); err != nil {
306 return err
307 }
308
309 return nil
310 }, opts...)
311 if e != nil {
312 return nil, "", e
313 }
314 it.Response = resp
315 return resp.GetDiscoveredApiObservations(), resp.GetNextPageToken(), nil
316 }
317
318 fetch := func(pageSize int, pageToken string) (string, error) {
319 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
320 if err != nil {
321 return "", err
322 }
323 it.items = append(it.items, items...)
324 return nextPageToken, nil
325 }
326
327 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
328 it.pageInfo.MaxSize = int(req.GetPageSize())
329 it.pageInfo.Token = req.GetPageToken()
330
331 return it
332 }
333
334 // GetDiscoveredApiObservation gets a DiscoveredAPIObservation in a given project, location and
335 // ApiObservation.
336 func (c *apiHubDiscoveryRESTClient) GetDiscoveredApiObservation(ctx context.Context, req *apihubpb.GetDiscoveredApiObservationRequest, opts ...gax.CallOption) (*apihubpb.DiscoveredApiObservation, error) {
337 baseUrl, err := url.Parse(c.endpoint)
338 if err != nil {
339 return nil, err
340 }
341 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
342
343 params := url.Values{}
344 params.Add("$alt", "json;enum-encoding=int")
345
346 baseUrl.RawQuery = params.Encode()
347
348 // Build HTTP headers from client and context metadata.
349 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
350
351 hds = append(c.xGoogHeaders, hds...)
352 hds = append(hds, "Content-Type", "application/json")
353 headers := gax.BuildHeaders(ctx, hds...)
354 opts = append((*c.CallOptions).GetDiscoveredApiObservation[0:len((*c.CallOptions).GetDiscoveredApiObservation):len((*c.CallOptions).GetDiscoveredApiObservation)], opts...)
355 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
356 resp := &apihubpb.DiscoveredApiObservation{}
357 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
358 if settings.Path != "" {
359 baseUrl.Path = settings.Path
360 }
361 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
362 if err != nil {
363 return err
364 }
365 httpReq = httpReq.WithContext(ctx)
366 httpReq.Header = headers
367
368 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDiscoveredApiObservation")
369 if err != nil {
370 return err
371 }
372
373 if err := unm.Unmarshal(buf, resp); err != nil {
374 return err
375 }
376
377 return nil
378 }, opts...)
379 if e != nil {
380 return nil, e
381 }
382 return resp, nil
383 }
384
385 // ListDiscoveredApiOperations lists all the DiscoveredAPIOperations in a given project, location and
386 // ApiObservation.
387 func (c *apiHubDiscoveryRESTClient) ListDiscoveredApiOperations(ctx context.Context, req *apihubpb.ListDiscoveredApiOperationsRequest, opts ...gax.CallOption) *DiscoveredApiOperationIterator {
388 it := &DiscoveredApiOperationIterator{}
389 req = proto.Clone(req).(*apihubpb.ListDiscoveredApiOperationsRequest)
390 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
391 it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.DiscoveredApiOperation, string, error) {
392 resp := &apihubpb.ListDiscoveredApiOperationsResponse{}
393 if pageToken != "" {
394 req.PageToken = pageToken
395 }
396 if pageSize > math.MaxInt32 {
397 req.PageSize = math.MaxInt32
398 } else if pageSize != 0 {
399 req.PageSize = int32(pageSize)
400 }
401 baseUrl, err := url.Parse(c.endpoint)
402 if err != nil {
403 return nil, "", err
404 }
405 baseUrl.Path += fmt.Sprintf("/v1/%v/discoveredApiOperations", req.GetParent())
406
407 params := url.Values{}
408 params.Add("$alt", "json;enum-encoding=int")
409 if req.GetPageSize() != 0 {
410 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
411 }
412 if req.GetPageToken() != "" {
413 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
414 }
415
416 baseUrl.RawQuery = params.Encode()
417
418 // Build HTTP headers from client and context metadata.
419 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
420 headers := gax.BuildHeaders(ctx, hds...)
421 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
422 if settings.Path != "" {
423 baseUrl.Path = settings.Path
424 }
425 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
426 if err != nil {
427 return err
428 }
429 httpReq.Header = headers
430
431 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDiscoveredApiOperations")
432 if err != nil {
433 return err
434 }
435 if err := unm.Unmarshal(buf, resp); err != nil {
436 return err
437 }
438
439 return nil
440 }, opts...)
441 if e != nil {
442 return nil, "", e
443 }
444 it.Response = resp
445 return resp.GetDiscoveredApiOperations(), resp.GetNextPageToken(), nil
446 }
447
448 fetch := func(pageSize int, pageToken string) (string, error) {
449 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
450 if err != nil {
451 return "", err
452 }
453 it.items = append(it.items, items...)
454 return nextPageToken, nil
455 }
456
457 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
458 it.pageInfo.MaxSize = int(req.GetPageSize())
459 it.pageInfo.Token = req.GetPageToken()
460
461 return it
462 }
463
464 // GetDiscoveredApiOperation gets a DiscoveredAPIOperation in a given project, location,
465 // ApiObservation and ApiOperation.
466 func (c *apiHubDiscoveryRESTClient) GetDiscoveredApiOperation(ctx context.Context, req *apihubpb.GetDiscoveredApiOperationRequest, opts ...gax.CallOption) (*apihubpb.DiscoveredApiOperation, error) {
467 baseUrl, err := url.Parse(c.endpoint)
468 if err != nil {
469 return nil, err
470 }
471 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
472
473 params := url.Values{}
474 params.Add("$alt", "json;enum-encoding=int")
475
476 baseUrl.RawQuery = params.Encode()
477
478 // Build HTTP headers from client and context metadata.
479 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
480
481 hds = append(c.xGoogHeaders, hds...)
482 hds = append(hds, "Content-Type", "application/json")
483 headers := gax.BuildHeaders(ctx, hds...)
484 opts = append((*c.CallOptions).GetDiscoveredApiOperation[0:len((*c.CallOptions).GetDiscoveredApiOperation):len((*c.CallOptions).GetDiscoveredApiOperation)], opts...)
485 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
486 resp := &apihubpb.DiscoveredApiOperation{}
487 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
488 if settings.Path != "" {
489 baseUrl.Path = settings.Path
490 }
491 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
492 if err != nil {
493 return err
494 }
495 httpReq = httpReq.WithContext(ctx)
496 httpReq.Header = headers
497
498 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDiscoveredApiOperation")
499 if err != nil {
500 return err
501 }
502
503 if err := unm.Unmarshal(buf, resp); err != nil {
504 return err
505 }
506
507 return nil
508 }, opts...)
509 if e != nil {
510 return nil, e
511 }
512 return resp, nil
513 }
514
515 // GetLocation gets information about a location.
516 func (c *apiHubDiscoveryRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
517 baseUrl, err := url.Parse(c.endpoint)
518 if err != nil {
519 return nil, err
520 }
521 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
522
523 params := url.Values{}
524 params.Add("$alt", "json;enum-encoding=int")
525
526 baseUrl.RawQuery = params.Encode()
527
528 // Build HTTP headers from client and context metadata.
529 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
530
531 hds = append(c.xGoogHeaders, hds...)
532 hds = append(hds, "Content-Type", "application/json")
533 headers := gax.BuildHeaders(ctx, hds...)
534 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
535 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
536 resp := &locationpb.Location{}
537 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
538 if settings.Path != "" {
539 baseUrl.Path = settings.Path
540 }
541 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
542 if err != nil {
543 return err
544 }
545 httpReq = httpReq.WithContext(ctx)
546 httpReq.Header = headers
547
548 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
549 if err != nil {
550 return err
551 }
552
553 if err := unm.Unmarshal(buf, resp); err != nil {
554 return err
555 }
556
557 return nil
558 }, opts...)
559 if e != nil {
560 return nil, e
561 }
562 return resp, nil
563 }
564
565 // ListLocations lists information about the supported locations for this service.
566 func (c *apiHubDiscoveryRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
567 it := &LocationIterator{}
568 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
569 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
570 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
571 resp := &locationpb.ListLocationsResponse{}
572 if pageToken != "" {
573 req.PageToken = pageToken
574 }
575 if pageSize > math.MaxInt32 {
576 req.PageSize = math.MaxInt32
577 } else if pageSize != 0 {
578 req.PageSize = int32(pageSize)
579 }
580 baseUrl, err := url.Parse(c.endpoint)
581 if err != nil {
582 return nil, "", err
583 }
584 baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName())
585
586 params := url.Values{}
587 params.Add("$alt", "json;enum-encoding=int")
588 if req.GetFilter() != "" {
589 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
590 }
591 if req.GetPageSize() != 0 {
592 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
593 }
594 if req.GetPageToken() != "" {
595 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
596 }
597
598 baseUrl.RawQuery = params.Encode()
599
600 // Build HTTP headers from client and context metadata.
601 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
602 headers := gax.BuildHeaders(ctx, hds...)
603 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
604 if settings.Path != "" {
605 baseUrl.Path = settings.Path
606 }
607 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
608 if err != nil {
609 return err
610 }
611 httpReq.Header = headers
612
613 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
614 if err != nil {
615 return err
616 }
617 if err := unm.Unmarshal(buf, resp); err != nil {
618 return err
619 }
620
621 return nil
622 }, opts...)
623 if e != nil {
624 return nil, "", e
625 }
626 it.Response = resp
627 return resp.GetLocations(), resp.GetNextPageToken(), nil
628 }
629
630 fetch := func(pageSize int, pageToken string) (string, error) {
631 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
632 if err != nil {
633 return "", err
634 }
635 it.items = append(it.items, items...)
636 return nextPageToken, nil
637 }
638
639 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
640 it.pageInfo.MaxSize = int(req.GetPageSize())
641 it.pageInfo.Token = req.GetPageToken()
642
643 return it
644 }
645
646 // CancelOperation is a utility method from google.longrunning.Operations.
647 func (c *apiHubDiscoveryRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
648 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
649 jsonReq, err := m.Marshal(req)
650 if err != nil {
651 return err
652 }
653
654 baseUrl, err := url.Parse(c.endpoint)
655 if err != nil {
656 return err
657 }
658 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
659
660 params := url.Values{}
661 params.Add("$alt", "json;enum-encoding=int")
662
663 baseUrl.RawQuery = params.Encode()
664
665 // Build HTTP headers from client and context metadata.
666 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
667
668 hds = append(c.xGoogHeaders, hds...)
669 hds = append(hds, "Content-Type", "application/json")
670 headers := gax.BuildHeaders(ctx, hds...)
671 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
672 if settings.Path != "" {
673 baseUrl.Path = settings.Path
674 }
675 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
676 if err != nil {
677 return err
678 }
679 httpReq = httpReq.WithContext(ctx)
680 httpReq.Header = headers
681
682 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
683 return err
684 }, opts...)
685 }
686
687 // DeleteOperation is a utility method from google.longrunning.Operations.
688 func (c *apiHubDiscoveryRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
689 baseUrl, err := url.Parse(c.endpoint)
690 if err != nil {
691 return err
692 }
693 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
694
695 params := url.Values{}
696 params.Add("$alt", "json;enum-encoding=int")
697
698 baseUrl.RawQuery = params.Encode()
699
700 // Build HTTP headers from client and context metadata.
701 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
702
703 hds = append(c.xGoogHeaders, hds...)
704 hds = append(hds, "Content-Type", "application/json")
705 headers := gax.BuildHeaders(ctx, hds...)
706 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
707 if settings.Path != "" {
708 baseUrl.Path = settings.Path
709 }
710 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
711 if err != nil {
712 return err
713 }
714 httpReq = httpReq.WithContext(ctx)
715 httpReq.Header = headers
716
717 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
718 return err
719 }, opts...)
720 }
721
722 // GetOperation is a utility method from google.longrunning.Operations.
723 func (c *apiHubDiscoveryRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
724 baseUrl, err := url.Parse(c.endpoint)
725 if err != nil {
726 return nil, err
727 }
728 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
729
730 params := url.Values{}
731 params.Add("$alt", "json;enum-encoding=int")
732
733 baseUrl.RawQuery = params.Encode()
734
735 // Build HTTP headers from client and context metadata.
736 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
737
738 hds = append(c.xGoogHeaders, hds...)
739 hds = append(hds, "Content-Type", "application/json")
740 headers := gax.BuildHeaders(ctx, hds...)
741 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
742 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
743 resp := &longrunningpb.Operation{}
744 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
745 if settings.Path != "" {
746 baseUrl.Path = settings.Path
747 }
748 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
749 if err != nil {
750 return err
751 }
752 httpReq = httpReq.WithContext(ctx)
753 httpReq.Header = headers
754
755 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
756 if err != nil {
757 return err
758 }
759
760 if err := unm.Unmarshal(buf, resp); err != nil {
761 return err
762 }
763
764 return nil
765 }, opts...)
766 if e != nil {
767 return nil, e
768 }
769 return resp, nil
770 }
771
772 // ListOperations is a utility method from google.longrunning.Operations.
773 func (c *apiHubDiscoveryRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
774 it := &OperationIterator{}
775 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
776 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
777 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
778 resp := &longrunningpb.ListOperationsResponse{}
779 if pageToken != "" {
780 req.PageToken = pageToken
781 }
782 if pageSize > math.MaxInt32 {
783 req.PageSize = math.MaxInt32
784 } else if pageSize != 0 {
785 req.PageSize = int32(pageSize)
786 }
787 baseUrl, err := url.Parse(c.endpoint)
788 if err != nil {
789 return nil, "", err
790 }
791 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
792
793 params := url.Values{}
794 params.Add("$alt", "json;enum-encoding=int")
795 if req.GetFilter() != "" {
796 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
797 }
798 if req.GetPageSize() != 0 {
799 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
800 }
801 if req.GetPageToken() != "" {
802 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
803 }
804
805 baseUrl.RawQuery = params.Encode()
806
807 // Build HTTP headers from client and context metadata.
808 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
809 headers := gax.BuildHeaders(ctx, hds...)
810 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
811 if settings.Path != "" {
812 baseUrl.Path = settings.Path
813 }
814 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
815 if err != nil {
816 return err
817 }
818 httpReq.Header = headers
819
820 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
821 if err != nil {
822 return err
823 }
824 if err := unm.Unmarshal(buf, resp); err != nil {
825 return err
826 }
827
828 return nil
829 }, opts...)
830 if e != nil {
831 return nil, "", e
832 }
833 it.Response = resp
834 return resp.GetOperations(), resp.GetNextPageToken(), nil
835 }
836
837 fetch := func(pageSize int, pageToken string) (string, error) {
838 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
839 if err != nil {
840 return "", err
841 }
842 it.items = append(it.items, items...)
843 return nextPageToken, nil
844 }
845
846 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
847 it.pageInfo.MaxSize = int(req.GetPageSize())
848 it.pageInfo.Token = req.GetPageToken()
849
850 return it
851 }