...

Text file src/google.golang.org/api/google-api-go-generator/testdata/floats.want

Documentation: google.golang.org/api/google-api-go-generator/testdata

     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 x provides access to the X.
     8//
     9// For product documentation, see: https://cloud.google.com/appengine/docs/admin-api/
    10//
    11// # Library status
    12//
    13// These client libraries are officially supported by Google. However, this
    14// library is considered complete and is in maintenance mode. This means
    15// that we will address critical bugs and security issues but will not add
    16// any new features.
    17//
    18// When possible, we recommend using our newer
    19// [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
    20// that are still actively being worked and iterated on.
    21//
    22// # Creating a client
    23//
    24// Usage example:
    25//
    26//	import "google.golang.org/api/x/v1"
    27//	...
    28//	ctx := context.Background()
    29//	xService, err := x.NewService(ctx)
    30//
    31// In this example, Google Application Default Credentials are used for
    32// authentication. For information on how to create and obtain Application
    33// Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    34//
    35// # Other authentication options
    36//
    37// To use an API key for authentication (note: some APIs do not support API
    38// keys), use [google.golang.org/api/option.WithAPIKey]:
    39//
    40//	xService, err := x.NewService(ctx, option.WithAPIKey("AIza..."))
    41//
    42// To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    43// flow, use [google.golang.org/api/option.WithTokenSource]:
    44//
    45//	config := &oauth2.Config{...}
    46//	// ...
    47//	token, err := config.Exchange(ctx, ...)
    48//	xService, err := x.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49//
    50// See [google.golang.org/api/option.ClientOption] for details on options.
    51package x // import "google.golang.org/api/x/v1"
    52
    53import (
    54	"bytes"
    55	"context"
    56	"encoding/json"
    57	"errors"
    58	"fmt"
    59	"io"
    60	"net/http"
    61	"net/url"
    62	"strconv"
    63	"strings"
    64
    65	googleapi "google.golang.org/api/googleapi"
    66	internal "google.golang.org/api/internal"
    67	gensupport "google.golang.org/api/internal/gensupport"
    68	option "google.golang.org/api/option"
    69	internaloption "google.golang.org/api/option/internaloption"
    70	htransport "google.golang.org/api/transport/http"
    71)
    72
    73// Always reference these packages, just in case the auto-generated code
    74// below doesn't.
    75var _ = bytes.NewBuffer
    76var _ = strconv.Itoa
    77var _ = fmt.Sprintf
    78var _ = json.NewDecoder
    79var _ = io.Copy
    80var _ = url.Parse
    81var _ = gensupport.MarshalJSON
    82var _ = googleapi.Version
    83var _ = errors.New
    84var _ = strings.Replace
    85var _ = context.Canceled
    86var _ = internaloption.WithDefaultEndpoint
    87var _ = internal.Version
    88
    89const apiId = "X:v1"
    90const apiName = "X"
    91const apiVersion = "v1"
    92const basePath = "https://appengine.googleapis.com/"
    93const basePathTemplate = "https://appengine.UNIVERSE_DOMAIN/"
    94const mtlsBasePath = "https://appengine.mtls.googleapis.com/"
    95
    96// NewService creates a new Service.
    97func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
    98	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
    99	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   100	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
   101	opts = append(opts, internaloption.EnableNewAuthLibrary())
   102	client, endpoint, err := htransport.NewClient(ctx, opts...)
   103	if err != nil {
   104		return nil, err
   105	}
   106	s, err := New(client)
   107	if err != nil {
   108		return nil, err
   109	}
   110	if endpoint != "" {
   111		s.BasePath = endpoint
   112	}
   113	return s, nil
   114}
   115
   116// New creates a new Service. It uses the provided http.Client for requests.
   117//
   118// Deprecated: please use NewService instead.
   119// To provide a custom HTTP client, use option.WithHTTPClient.
   120// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   121func New(client *http.Client) (*Service, error) {
   122	if client == nil {
   123		return nil, errors.New("client is nil")
   124	}
   125	s := &Service{client: client, BasePath: basePath}
   126	return s, nil
   127}
   128
   129type Service struct {
   130	client    *http.Client
   131	BasePath  string // API endpoint base URL
   132	UserAgent string // optional additional User-Agent fragment
   133}
   134
   135func (s *Service) userAgent() string {
   136	if s.UserAgent == "" {
   137		return googleapi.UserAgent
   138	}
   139	return googleapi.UserAgent + " " + s.UserAgent
   140}
   141
   142// Utilization: CPU utilization policy.
   143type Utilization struct {
   144	Average float64 `json:"average,omitempty"`
   145	Count   int64   `json:"count,omitempty"`
   146	Target  float64 `json:"target,omitempty"`
   147	// ForceSendFields is a list of field names (e.g. "Average") to unconditionally
   148	// include in API requests. By default, fields with empty or default values are
   149	// omitted from API requests. See
   150	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   151	// details.
   152	ForceSendFields []string `json:"-"`
   153	// NullFields is a list of field names (e.g. "Average") to include in API
   154	// requests with the JSON null value. By default, fields with empty values are
   155	// omitted from API requests. See
   156	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   157	NullFields []string `json:"-"`
   158}
   159
   160func (s *Utilization) MarshalJSON() ([]byte, error) {
   161	type NoMethod Utilization
   162	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   163}
   164
   165func (s *Utilization) UnmarshalJSON(data []byte) error {
   166	type NoMethod Utilization
   167	var s1 struct {
   168		Average gensupport.JSONFloat64 `json:"average"`
   169		Target  gensupport.JSONFloat64 `json:"target"`
   170		*NoMethod
   171	}
   172	s1.NoMethod = (*NoMethod)(s)
   173	if err := json.Unmarshal(data, &s1); err != nil {
   174		return err
   175	}
   176	s.Average = float64(s1.Average)
   177	s.Target = float64(s1.Target)
   178	return nil
   179}

View as plain text