1// Copyright YEAR Google LLC.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Code generated file. DO NOT EDIT.
6
7// Package getwithoutbody provides access to the Example API.
8//
9// # Library status
10//
11// These client libraries are officially supported by Google. However, this
12// library is considered complete and is in maintenance mode. This means
13// that we will address critical bugs and security issues but will not add
14// any new features.
15//
16// When possible, we recommend using our newer
17// [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
18// that are still actively being worked and iterated on.
19//
20// # Creating a client
21//
22// Usage example:
23//
24// import "google.golang.org/api/getwithoutbody/v1"
25// ...
26// ctx := context.Background()
27// getwithoutbodyService, err := getwithoutbody.NewService(ctx)
28//
29// In this example, Google Application Default Credentials are used for
30// authentication. For information on how to create and obtain Application
31// Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
32//
33// # Other authentication options
34//
35// To use an API key for authentication (note: some APIs do not support API
36// keys), use [google.golang.org/api/option.WithAPIKey]:
37//
38// getwithoutbodyService, err := getwithoutbody.NewService(ctx, option.WithAPIKey("AIza..."))
39//
40// To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
41// flow, use [google.golang.org/api/option.WithTokenSource]:
42//
43// config := &oauth2.Config{...}
44// // ...
45// token, err := config.Exchange(ctx, ...)
46// getwithoutbodyService, err := getwithoutbody.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
47//
48// See [google.golang.org/api/option.ClientOption] for details on options.
49package getwithoutbody // import "google.golang.org/api/getwithoutbody/v1"
50
51import (
52 "bytes"
53 "context"
54 "encoding/json"
55 "errors"
56 "fmt"
57 "io"
58 "net/http"
59 "net/url"
60 "strconv"
61 "strings"
62
63 googleapi "google.golang.org/api/googleapi"
64 internal "google.golang.org/api/internal"
65 gensupport "google.golang.org/api/internal/gensupport"
66 option "google.golang.org/api/option"
67 internaloption "google.golang.org/api/option/internaloption"
68 htransport "google.golang.org/api/transport/http"
69)
70
71// Always reference these packages, just in case the auto-generated code
72// below doesn't.
73var _ = bytes.NewBuffer
74var _ = strconv.Itoa
75var _ = fmt.Sprintf
76var _ = json.NewDecoder
77var _ = io.Copy
78var _ = url.Parse
79var _ = gensupport.MarshalJSON
80var _ = googleapi.Version
81var _ = errors.New
82var _ = strings.Replace
83var _ = context.Canceled
84var _ = internaloption.WithDefaultEndpoint
85var _ = internal.Version
86
87const apiId = "getwithoutbody:v1"
88const apiName = "getwithoutbody"
89const apiVersion = "v1"
90const basePath = "https://www.googleapis.com/discovery/v1/apis"
91const basePathTemplate = "https://www.UNIVERSE_DOMAIN/discovery/v1/apis"
92
93// NewService creates a new Service.
94func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
95 opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
96 opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
97 opts = append(opts, internaloption.EnableNewAuthLibrary())
98 client, endpoint, err := htransport.NewClient(ctx, opts...)
99 if err != nil {
100 return nil, err
101 }
102 s, err := New(client)
103 if err != nil {
104 return nil, err
105 }
106 if endpoint != "" {
107 s.BasePath = endpoint
108 }
109 return s, nil
110}
111
112// New creates a new Service. It uses the provided http.Client for requests.
113//
114// Deprecated: please use NewService instead.
115// To provide a custom HTTP client, use option.WithHTTPClient.
116// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
117func New(client *http.Client) (*Service, error) {
118 if client == nil {
119 return nil, errors.New("client is nil")
120 }
121 s := &Service{client: client, BasePath: basePath}
122 s.MetricDescriptors = NewMetricDescriptorsService(s)
123 return s, nil
124}
125
126type Service struct {
127 client *http.Client
128 BasePath string // API endpoint base URL
129 UserAgent string // optional additional User-Agent fragment
130
131 MetricDescriptors *MetricDescriptorsService
132}
133
134func (s *Service) userAgent() string {
135 if s.UserAgent == "" {
136 return googleapi.UserAgent
137 }
138 return googleapi.UserAgent + " " + s.UserAgent
139}
140
141func NewMetricDescriptorsService(s *Service) *MetricDescriptorsService {
142 rs := &MetricDescriptorsService{s: s}
143 return rs
144}
145
146type MetricDescriptorsService struct {
147 s *Service
148}
149
150// ListMetricRequest: The request of getwithoutbody.metricDescriptors.list.
151type ListMetricRequest struct {
152 // Kind: Identifies what kind of resource this is. Value: the fixed string
153 // "getwithoutbody#listMetricRequest".
154 Kind string `json:"kind,omitempty"`
155 // ForceSendFields is a list of field names (e.g. "Kind") to unconditionally
156 // include in API requests. By default, fields with empty or default values are
157 // omitted from API requests. See
158 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
159 // details.
160 ForceSendFields []string `json:"-"`
161 // NullFields is a list of field names (e.g. "Kind") to include in API requests
162 // with the JSON null value. By default, fields with empty values are omitted
163 // from API requests. See
164 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
165 NullFields []string `json:"-"`
166}
167
168func (s *ListMetricRequest) MarshalJSON() ([]byte, error) {
169 type NoMethod ListMetricRequest
170 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
171}
172
173// ListMetricResponse: The response of getwithoutbody.metricDescriptors.list.
174type ListMetricResponse struct {
175 // Kind: Identifies what kind of resource this is. Value: the fixed string
176 // "getwithoutbody#listMetricResponse".
177 Kind string `json:"kind,omitempty"`
178 // NextPageToken: Pagination token. If present, indicates that additional
179 // results are available for retrieval. To access the results past the
180 // pagination limit, set this value to the pageToken query parameter.
181 NextPageToken string `json:"nextPageToken,omitempty"`
182
183 // ServerResponse contains the HTTP response code and headers from the server.
184 googleapi.ServerResponse `json:"-"`
185 // ForceSendFields is a list of field names (e.g. "Kind") to unconditionally
186 // include in API requests. By default, fields with empty or default values are
187 // omitted from API requests. See
188 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
189 // details.
190 ForceSendFields []string `json:"-"`
191 // NullFields is a list of field names (e.g. "Kind") to include in API requests
192 // with the JSON null value. By default, fields with empty values are omitted
193 // from API requests. See
194 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
195 NullFields []string `json:"-"`
196}
197
198func (s *ListMetricResponse) MarshalJSON() ([]byte, error) {
199 type NoMethod ListMetricResponse
200 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
201}
202
203type MetricDescriptorsListCall struct {
204 s *Service
205 project string
206 listmetricrequest *ListMetricRequest
207 urlParams_ gensupport.URLParams
208 ifNoneMatch_ string
209 ctx_ context.Context
210 header_ http.Header
211}
212
213// List: List all of the available metric descriptors. Large number of metric
214// descriptors will be paginated, use the nextPageToken returned in the
215// response to request subsequent pages of results by setting the pageToken
216// query parameter to the value of the nextPageToken.
217//
218// - project: The project id. The value can be the numeric project ID or
219// string-based project name.
220func (r *MetricDescriptorsService) List(project string, listmetricrequest *ListMetricRequest) *MetricDescriptorsListCall {
221 c := &MetricDescriptorsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
222 c.project = project
223 c.listmetricrequest = listmetricrequest
224 return c
225}
226
227// Count sets the optional parameter "count": Maximum number of metric
228// descriptors per page. Used for pagination. If not specified, count = 100.
229func (c *MetricDescriptorsListCall) Count(count int64) *MetricDescriptorsListCall {
230 c.urlParams_.Set("count", fmt.Sprint(count))
231 return c
232}
233
234// PageToken sets the optional parameter "pageToken": The pagination token,
235// which is used to page through large result sets. Set this value to the value
236// of the nextPageToken to retrieve the next page of results.
237func (c *MetricDescriptorsListCall) PageToken(pageToken string) *MetricDescriptorsListCall {
238 c.urlParams_.Set("pageToken", pageToken)
239 return c
240}
241
242// Fields allows partial responses to be retrieved. See
243// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
244// details.
245func (c *MetricDescriptorsListCall) Fields(s ...googleapi.Field) *MetricDescriptorsListCall {
246 c.urlParams_.Set("fields", googleapi.CombineFields(s))
247 return c
248}
249
250// IfNoneMatch sets an optional parameter which makes the operation fail if the
251// object's ETag matches the given value. This is useful for getting updates
252// only after the object has changed since the last request.
253func (c *MetricDescriptorsListCall) IfNoneMatch(entityTag string) *MetricDescriptorsListCall {
254 c.ifNoneMatch_ = entityTag
255 return c
256}
257
258// Context sets the context to be used in this call's Do method.
259func (c *MetricDescriptorsListCall) Context(ctx context.Context) *MetricDescriptorsListCall {
260 c.ctx_ = ctx
261 return c
262}
263
264// Header returns a http.Header that can be modified by the caller to add
265// headers to the request.
266func (c *MetricDescriptorsListCall) Header() http.Header {
267 if c.header_ == nil {
268 c.header_ = make(http.Header)
269 }
270 return c.header_
271}
272
273func (c *MetricDescriptorsListCall) doRequest(alt string) (*http.Response, error) {
274 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
275 if c.ifNoneMatch_ != "" {
276 reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
277 }
278 var body io.Reader = nil
279 c.urlParams_.Set("alt", alt)
280 c.urlParams_.Set("prettyPrint", "false")
281 urls := googleapi.ResolveRelative(c.s.BasePath, "{project}/metricDescriptors")
282 urls += "?" + c.urlParams_.Encode()
283 req, err := http.NewRequest("GET", urls, body)
284 if err != nil {
285 return nil, err
286 }
287 req.Header = reqHeaders
288 googleapi.Expand(req.URL, map[string]string{
289 "project": c.project,
290 })
291 return gensupport.SendRequest(c.ctx_, c.s.client, req)
292}
293
294// Do executes the "getwithoutbody.metricDescriptors.list" call.
295// Any non-2xx status code is an error. Response headers are in either
296// *ListMetricResponse.ServerResponse.Header or (if a response was returned at
297// all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
298// check whether the returned error was because http.StatusNotModified was
299// returned.
300func (c *MetricDescriptorsListCall) Do(opts ...googleapi.CallOption) (*ListMetricResponse, error) {
301 gensupport.SetOptions(c.urlParams_, opts...)
302 res, err := c.doRequest("json")
303 if res != nil && res.StatusCode == http.StatusNotModified {
304 if res.Body != nil {
305 res.Body.Close()
306 }
307 return nil, gensupport.WrapError(&googleapi.Error{
308 Code: res.StatusCode,
309 Header: res.Header,
310 })
311 }
312 if err != nil {
313 return nil, err
314 }
315 defer googleapi.CloseBody(res)
316 if err := googleapi.CheckResponse(res); err != nil {
317 return nil, gensupport.WrapError(err)
318 }
319 ret := &ListMetricResponse{
320 ServerResponse: googleapi.ServerResponse{
321 Header: res.Header,
322 HTTPStatusCode: res.StatusCode,
323 },
324 }
325 target := &ret
326 if err := gensupport.DecodeResponse(target, res); err != nil {
327 return nil, err
328 }
329 return ret, nil
330}
331
332// Pages invokes f for each page of results.
333// A non-nil error returned from f will halt the iteration.
334// The provided context supersedes any context provided to the Context method.
335func (c *MetricDescriptorsListCall) Pages(ctx context.Context, f func(*ListMetricResponse) error) error {
336 c.ctx_ = ctx
337 defer c.PageToken(c.urlParams_.Get("pageToken"))
338 for {
339 x, err := c.Do()
340 if err != nil {
341 return err
342 }
343 if err := f(x); err != nil {
344 return err
345 }
346 if x.NextPageToken == "" {
347 return nil
348 }
349 c.PageToken(x.NextPageToken)
350 }
351}
View as plain text