Skip to content

Commit

Permalink
google-api-go-client/all: Move nil media check to callers.
Browse files Browse the repository at this point in the history
ConditionallyIncludeMedia does nothing if media is nil.

Simplify by not calling this function if media is nil.

Change-Id: I4657a0c5a7e02b78d28317b3bab94f713261ced9
Reviewed-on: https://code-review.googlesource.com/3976
Reviewed-by: Michael McGreevy <[email protected]>
  • Loading branch information
mcgreevy committed Jan 7, 2016
1 parent 7285216 commit 77e7d38
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 107 deletions.
4 changes: 2 additions & 2 deletions admin/email_migration/v2/admin-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ func (c *MailInsertCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions analytics/v3/analytics-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14548,8 +14548,8 @@ func (c *ManagementUploadsUploadDataCall) doRequest(alt string) (*http.Response,
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
12 changes: 6 additions & 6 deletions androidpublisher/v2/androidpublisher-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3454,8 +3454,8 @@ func (c *EditsApksUploadCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -4666,8 +4666,8 @@ func (c *EditsExpansionfilesUploadCall) doRequest(alt string) (*http.Response, e
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -5453,8 +5453,8 @@ func (c *EditsImagesUploadCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions bigquery/v2/bigquery-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3641,8 +3641,8 @@ func (c *JobsInsertCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions dataproc/v1/dataproc-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ func (c *MediaUploadCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions dfareporting/v2.0/dfareporting-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18270,8 +18270,8 @@ func (c *CreativeAssetsInsertCall) doRequest(alt string) (*http.Response, error)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions dfareporting/v2.1/dfareporting-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19769,8 +19769,8 @@ func (c *CreativeAssetsInsertCall) doRequest(alt string) (*http.Response, error)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions dfareporting/v2.2/dfareporting-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19793,8 +19793,8 @@ func (c *CreativeAssetsInsertCall) doRequest(alt string) (*http.Response, error)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions dfareporting/v2.3/dfareporting-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19813,8 +19813,8 @@ func (c *CreativeAssetsInsertCall) doRequest(alt string) (*http.Response, error)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
8 changes: 4 additions & 4 deletions drive/v1/drive-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ func (c *FilesInsertCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -989,8 +989,8 @@ func (c *FilesUpdateCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("PUT", urls, body)
Expand Down
12 changes: 6 additions & 6 deletions drive/v2/drive-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5827,8 +5827,8 @@ func (c *FilesInsertCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -7194,8 +7194,8 @@ func (c *FilesUpdateCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("PUT", urls, body)
Expand Down Expand Up @@ -10399,8 +10399,8 @@ func (c *RealtimeUpdateCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("PUT", urls, body)
Expand Down
8 changes: 4 additions & 4 deletions drive/v3/drive-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3202,8 +3202,8 @@ func (c *FilesCreateCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -4379,8 +4379,8 @@ func (c *FilesUpdateCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("PATCH", urls, body)
Expand Down
8 changes: 4 additions & 4 deletions fusiontables/v1/fusiontables-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3549,8 +3549,8 @@ func (c *TableImportRowsCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -3810,8 +3810,8 @@ func (c *TableImportTableCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
12 changes: 6 additions & 6 deletions fusiontables/v2/fusiontables-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3610,8 +3610,8 @@ func (c *TableImportRowsCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -3871,8 +3871,8 @@ func (c *TableImportTableCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -4570,8 +4570,8 @@ func (c *TableReplaceRowsCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions gamesconfiguration/v1configuration/gamesconfiguration-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,8 +1450,8 @@ func (c *ImageConfigurationsUploadCall) doRequest(alt string) (*http.Response, e
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
7 changes: 2 additions & 5 deletions gensupport/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (sct *ContentSniffer) ContentType() (string, bool) {
return sct.ctype, true
}

// ConditionallyIncludeMedia does nothing if media is nil.
// IncludeMedia combines an existing HTTP body with media content to create a multipart/related HTTP body.
//
// bodyp is an in/out parameter. It should initially point to the
// reader of the application/json (or whatever) payload to send in the
Expand All @@ -81,10 +81,7 @@ func (sct *ContentSniffer) ContentType() (string, bool) {
// to the "multipart/related" content type, with random boundary.
//
// The return value is a function that can be used to close the bodyp Reader with an error.
func ConditionallyIncludeMedia(media io.Reader, bodyp *io.Reader, ctypep *string) func() {
if media == nil {
return func() {}
}
func IncludeMedia(media io.Reader, bodyp *io.Reader, ctypep *string) func() {
var mediaType string
media, mediaType = getMediaType(media)

Expand Down
24 changes: 12 additions & 12 deletions gmail/v1/gmail-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,8 @@ func (c *UsersDraftsCreateCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -2070,8 +2070,8 @@ func (c *UsersDraftsSendCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -2302,8 +2302,8 @@ func (c *UsersDraftsUpdateCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("PUT", urls, body)
Expand Down Expand Up @@ -3943,8 +3943,8 @@ func (c *UsersMessagesImportCall) doRequest(alt string) (*http.Response, error)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -4227,8 +4227,8 @@ func (c *UsersMessagesInsertCall) doRequest(alt string) (*http.Response, error)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down Expand Up @@ -4835,8 +4835,8 @@ func (c *UsersMessagesSendCall) doRequest(alt string) (*http.Response, error) {
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
4 changes: 2 additions & 2 deletions google-api-go-generator/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1823,8 +1823,8 @@ func (meth *Method) generateCode() {
pn(`ctype := "application/json"`)
hasContentType = true
}
pn(`if c.protocol_ != "resumable" {`)
pn(" cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)")
pn(`if c.protocol_ != "resumable" && c.media_ != nil {`)
pn(" cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)")
pn(" defer cancel()")
pn("}")
}
Expand Down
4 changes: 2 additions & 2 deletions groupsmigration/v1/groupsmigration-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ func (c *ArchiveInsertCall) doRequest(alt string) (*http.Response, error) {
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
cancel := gensupport.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if c.protocol_ != "resumable" && c.media_ != nil {
cancel := gensupport.IncludeMedia(c.media_, &body, &ctype)
defer cancel()
}
req, _ := http.NewRequest("POST", urls, body)
Expand Down
Loading

0 comments on commit 77e7d38

Please sign in to comment.