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