Debian Codegraph @

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