You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

399 regels
13 KiB

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