googleapi: use RawPath, not Opaque, for template expansion

Historically the google-api-go-client has had trouble sending certain
characters in paths without the Go standard library (net/url and
net/http packages) double escaping or escaping in an unexpected manner
(for example, space encoding in issue #64).

As a workaround, we started escaping the URL manually and using
url.Opaque (for example, 02cfcab and 5c258d4). This mostly works but has
problems with HTTP/2 (golang/go#16847). In Go 1.5, the URL struct
introduced the RawPath field which was more suitable for this task: if
RawPath is provided and is a valid escaping of Path, then the url
package will use it as the value of EscapedPath (and EscapedPath is then
subsequently used when constructing HTTP requests etc.).

This commit changes uritemplates.Expand to return both the unescaped and
escaped forms of the the template expansion. This allows us to fill in
both url.Path and url.RawPath in a way that satisfies the criteria for
url.EscapedPath to function correctly.

Issue #161.

Change-Id: I51e54e18f198b6465a6d032b1072282bf3d2f9ce
Reviewed-on: https://code-review.googlesource.com/7110
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
6 files changed
tree: cb8b5c8141cf19c8d7869c6171450e0115de770c
  1. acceleratedmobilepageurl/
  2. adexchangebuyer/
  3. adexchangebuyer2/
  4. adexchangeseller/
  5. admin/
  6. adsense/
  7. adsensehost/
  8. analytics/
  9. analyticsreporting/
  10. androidenterprise/
  11. androidpublisher/
  12. appengine/
  13. appsactivity/
  14. appstate/
  15. autoscaler/
  16. bigquery/
  17. blogger/
  18. books/
  19. calendar/
  20. civicinfo/
  21. classroom/
  22. cloudbilling/
  23. cloudbuild/
  24. clouddebugger/
  25. clouderrorreporting/
  26. cloudlatencytest/
  27. cloudmonitoring/
  28. cloudresourcemanager/
  29. cloudtrace/
  30. clouduseraccounts/
  31. compute/
  32. consumersurveys/
  33. container/
  34. content/
  35. coordinate/
  36. customsearch/
  37. dataflow/
  38. dataproc/
  39. datastore/
  40. deploymentmanager/
  41. dfareporting/
  42. discovery/
  43. dns/
  44. doubleclickbidmanager/
  45. doubleclicksearch/
  46. drive/
  47. examples/
  48. firebaserules/
  49. fitness/
  50. freebase/
  51. fusiontables/
  52. games/
  53. gamesconfiguration/
  54. gamesmanagement/
  55. gan/
  56. genomics/
  57. gensupport/
  58. gmail/
  59. google-api-go-generator/
  60. googleapi/
  61. groupsmigration/
  62. groupssettings/
  63. iam/
  64. identitytoolkit/
  65. integration-tests/
  66. internal/
  67. iterator/
  68. kgsearch/
  69. language/
  70. lib/
  71. licensing/
  72. logging/
  73. manager/
  74. mapsengine/
  75. mirror/
  76. monitoring/
  77. oauth2/
  78. option/
  79. pagespeedonline/
  80. partners/
  81. people/
  82. playmoviespartner/
  83. plus/
  84. plusdomains/
  85. prediction/
  86. proximitybeacon/
  87. pubsub/
  88. qpxexpress/
  89. replicapool/
  90. replicapoolupdater/
  91. reseller/
  92. resourceviews/
  93. runtimeconfig/
  94. safebrowsing/
  95. script/
  96. servicecontrol/
  97. servicemanagement/
  98. serviceregistry/
  99. sheets/
  100. siteverification/
  101. spectrum/
  102. speech/
  103. sqladmin/
  104. storage/
  105. storagetransfer/
  106. tagmanager/
  107. taskqueue/
  108. tasks/
  109. toolresults/
  110. translate/
  111. transport/
  112. urlshortener/
  113. vision/
  114. webfonts/
  115. webmasters/
  116. youtube/
  117. youtubeanalytics/
  118. youtubereporting/
  119. .hgignore
  120. .hgtags
  121. .travis.yml
  122. api-list.json
  123. AUTHORS
  124. CONTRIBUTING.md
  125. CONTRIBUTORS
  126. GettingStarted.md
  127. key.json.enc
  128. LICENSE
  129. Makefile
  130. NOTES
  131. README.md
  132. TODO
README.md

Google APIs Client Library for Go

Status

Build Status

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.

Announcement email:

Getting started documentation:

In summary:

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

For docs, see e.g.:

The package of a given import is the second-to-last component, before the version number.

For examples, see:

For support, use the golang-nuts@ mailing list:

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 (
        "golang.org/x/net/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.