monitoring: add special case for MService; revert Service->APIService

In https://github.com/googleapis/google-api-go-client/commit/8a410c21381766a810817fd6200fce8838ecb277,
monitoring/v3 got a new schema (item in field "schemas") named "Service". This
meant that when the generator generated the API, the name "Service" was already
a named type by the time the generator got to creating the "New" method and
corresponding struct.

So, the generator picked the next item in the "serviceTypes" list to describe
the monitoring service: New() *Service became New() *APIService. This is a
breaking change.

We don't guarantee backwards compatibility (https://godoc.org/google.golang.org/api#hdr-Versioning_and_Stability),
but this API is widely depended upon and worthy of making an exception.

This CL introduces some mapping from monitoring's Service field to
MService. It re-maps the original doc's type in-place, and then any time a
ref is requested with name Service it instead requests MService.

Fixes #425.

Change-Id: I8869a7e9b08ce7e42a9f38abf9a6d5810065efc0
Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/48591
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Broadfoot <cbro@google.com>
2 files changed
tree: c0f90420c7f53a78ceed8121e637b95753d2915a
  1. abusiveexperiencereport/
  2. acceleratedmobilepageurl/
  3. accessapproval/
  4. accesscontextmanager/
  5. adexchangebuyer/
  6. adexchangebuyer2/
  7. adexchangeseller/
  8. adexperiencereport/
  9. admin/
  10. adsense/
  11. adsensehost/
  12. alertcenter/
  13. analytics/
  14. analyticsreporting/
  15. androiddeviceprovisioning/
  16. androidenterprise/
  17. androidmanagement/
  18. androidpublisher/
  19. apigee/
  20. appengine/
  21. appsactivity/
  22. appstate/
  23. bigquery/
  24. bigqueryconnection/
  25. bigquerydatatransfer/
  26. bigqueryreservation/
  27. bigtableadmin/
  28. billingbudgets/
  29. binaryauthorization/
  30. blogger/
  31. books/
  32. calendar/
  33. chat/
  34. civicinfo/
  35. classroom/
  36. cloudasset/
  37. cloudbilling/
  38. cloudbuild/
  39. cloudcommerceprocurement/
  40. clouddebugger/
  41. clouderrorreporting/
  42. cloudfunctions/
  43. cloudidentity/
  44. cloudiot/
  45. cloudkms/
  46. cloudprivatecatalog/
  47. cloudprivatecatalogproducer/
  48. cloudprofiler/
  49. cloudresourcemanager/
  50. cloudscheduler/
  51. cloudsearch/
  52. cloudshell/
  53. cloudtasks/
  54. cloudtrace/
  55. commentanalyzer/
  56. composer/
  57. compute/
  58. consumersurveys/
  59. container/
  60. containeranalysis/
  61. content/
  62. customsearch/
  63. datacatalog/
  64. dataflow/
  65. datafusion/
  66. dataproc/
  67. datastore/
  68. deploymentmanager/
  69. dfareporting/
  70. dialogflow/
  71. digitalassetlinks/
  72. discovery/
  73. dlp/
  74. dns/
  75. docs/
  76. domainsrdap/
  77. doubleclickbidmanager/
  78. doubleclicksearch/
  79. drive/
  80. driveactivity/
  81. examples/
  82. factchecktools/
  83. fcm/
  84. file/
  85. firebase/
  86. firebasedynamiclinks/
  87. firebasehosting/
  88. firebaseremoteconfig/
  89. firebaserules/
  90. firestore/
  91. fitness/
  92. fusiontables/
  93. games/
  94. gamesconfiguration/
  95. gamesmanagement/
  96. genomics/
  97. gmail/
  98. google-api-go-generator/
  99. googleapi/
  100. groupsmigration/
  101. groupssettings/
  102. healthcare/
  103. homegraph/
  104. iam/
  105. iamcredentials/
  106. iap/
  107. identitytoolkit/
  108. indexing/
  109. integration-tests/
  110. internal/
  111. iterator/
  112. jobs/
  113. kgsearch/
  114. language/
  115. lib/
  116. libraryagent/
  117. licensing/
  118. lifesciences/
  119. logging/
  120. manufacturers/
  121. mirror/
  122. ml/
  123. monitoring/
  124. oauth2/
  125. option/
  126. oslogin/
  127. pagespeedonline/
  128. partners/
  129. people/
  130. playcustomapp/
  131. playmoviespartner/
  132. plus/
  133. plusdomains/
  134. policytroubleshooter/
  135. poly/
  136. proximitybeacon/
  137. pubsub/
  138. qpxexpress/
  139. recommender/
  140. redis/
  141. remotebuildexecution/
  142. replicapool/
  143. replicapoolupdater/
  144. reseller/
  145. run/
  146. runtimeconfig/
  147. safebrowsing/
  148. script/
  149. searchconsole/
  150. secretmanager/
  151. securitycenter/
  152. servicebroker/
  153. serviceconsumermanagement/
  154. servicecontrol/
  155. servicemanagement/
  156. servicenetworking/
  157. serviceusage/
  158. serviceuser/
  159. sheets/
  160. siteverification/
  161. slides/
  162. sourcerepo/
  163. spanner/
  164. spectrum/
  165. speech/
  166. sql/
  167. sqladmin/
  168. storage/
  169. storagetransfer/
  170. streetviewpublish/
  171. support/
  172. surveys/
  173. tagmanager/
  174. tasks/
  175. testing/
  176. texttospeech/
  177. toolresults/
  178. tpu/
  179. tracing/
  180. translate/
  181. transport/
  182. urlshortener/
  183. vault/
  184. verifiedaccess/
  185. videointelligence/
  186. vision/
  187. webfonts/
  188. webmasters/
  189. websecurityscanner/
  190. youtube/
  191. youtubeanalytics/
  192. youtubereporting/
  193. .gitignore
  194. .hgtags
  195. api-list.json
  196. AUTHORS
  197. CHANGES.md
  198. CONTRIBUTING.md
  199. CONTRIBUTORS
  200. doc.go
  201. GettingStarted.md
  202. go.mod
  203. go.sum
  204. LICENSE
  205. license_test.go
  206. NOTES
  207. README.md
  208. RELEASING.md
  209. TODO
  210. tools.go
README.md

Google APIs Client Library for Go

Getting Started

$ go get google.golang.org/api/tasks/v1
$ go get google.golang.org/api/moderator/v1
$ go get google.golang.org/api/urlshortener/v1
... etc ...

and using:

package main

import (
	"net/http"

	"google.golang.org/api/urlshortener/v1"
)

func main() {
	svc, err := urlshortener.New(http.DefaultClient)
	// ...
}

Status

GoDoc

These are auto-generated Go libraries from the Google Discovery Service's JSON description files of the available “new style” Google APIs.

Due to the auto-generated nature of this collection of libraries, complete APIs or specific versions can appear or go away without notice. As a result, you should always locally vendor any API(s) that your code relies upon.

These client libraries are officially supported by Google. However, the libraries are considered complete and are in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.

If you're working with Google Cloud Platform APIs such as Datastore or Pub/Sub, consider using the Cloud Client Libraries for Go instead. These are the new and idiomatic Go libraries targeted specifically at Google Cloud Platform Services.

The generator itself and the code it produces are beta. Some APIs are alpha/beta, and indicated as such in the import path (e.g., “google.golang.org/api/someapi/v1alpha”).

Application Default Credentials Example

Application Default Credentials provide a simplified way to obtain credentials for authenticating with Google APIs.

The Application Default Credentials authenticate as the application itself, which make them great for working with Google Cloud APIs like Storage or Datastore. They are the recommended form of authentication when building applications that run on Google Compute Engine or Google App Engine.

Default credentials are provided by the golang.org/x/oauth2/google package. To use them, add the following import:

import "golang.org/x/oauth2/google"

Some credentials types require you to specify scopes, and service entry points may not inject them. If you encounter this situation you may need to specify scopes as follows:

import (
        "context"
        "golang.org/x/oauth2/google"
        "google.golang.org/api/compute/v1"
)

func main() {
        // Use oauth2.NoContext if there isn't a good context to pass in.
        ctx := context.Background()

        client, err := google.DefaultClient(ctx, compute.ComputeScope)
        if err != nil {
                //...
        }
        computeService, err := compute.New(client)
        if err != nil {
                //...
        }
}

If you need a oauth2.TokenSource, use the DefaultTokenSource function:

ts, err := google.DefaultTokenSource(ctx, scope1, scope2, ...)
if err != nil {
        //...
}
client := oauth2.NewClient(ctx, ts)

See also: golang.org/x/oauth2/google package documentation.