本文整理汇总了Golang中google/golang.org/api/googleapi.ConditionallyIncludeMedia函数的典型用法代码示例。如果您正苦于以下问题:Golang ConditionallyIncludeMedia函数的具体用法?Golang ConditionallyIncludeMedia怎么用?Golang ConditionallyIncludeMedia使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ConditionallyIncludeMedia函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: doRequest
func (c *FilesUpdateCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
if err != nil {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", alt)
if v, ok := c.opt_["newRevision"]; ok {
params.Set("newRevision", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateModifiedDate"]; ok {
params.Set("updateModifiedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateViewedDate"]; ok {
params.Set("updateViewedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("PUT", urls, body)
googleapi.Expand(req.URL, map[string]string{
"id": c.id,
})
if c.protocol_ == "resumable" {
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}
开发者ID:rkazak,项目名称:distribution,代码行数:53,代码来源:drive-gen.go
示例2: doRequest
func (c *ArchiveInsertCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
params := make(url.Values)
params.Set("alt", alt)
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "{groupId}/archive")
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"groupId": c.groupId,
})
if c.protocol_ == "resumable" {
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}
开发者ID:ryanharper,项目名称:google-api-go-client,代码行数:41,代码来源:groupsmigration-gen.go
示例3: doRequest
func (c *MailInsertCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.mailitem)
if err != nil {
return nil, err
}
ctype := "application/json"
c.urlParams_.Set("alt", alt)
urls := googleapi.ResolveRelative(c.s.BasePath, "{userKey}/mail")
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"userKey": c.userKey,
})
if c.protocol_ == "resumable" {
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}
开发者ID:4shome,项目名称:google-api-go-client,代码行数:40,代码来源:admin-gen.go
示例4: Do
func (c *MailInsertCall) Do() error {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.mailitem)
if err != nil {
return err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "{userKey}/mail")
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"userKey": c.userKey,
})
if c.protocol_ == "resumable" {
req.ContentLength = 0
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Body = nil
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return err
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Client: c.s.client,
UserAgent: c.s.userAgent(),
URI: loc,
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
return err
}
defer res.Body.Close()
}
return nil
// {
// "description": "Insert Mail into Google's Gmail backends",
// "httpMethod": "POST",
// "id": "emailMigration.mail.insert",
// "mediaUpload": {
// "accept": [
// "message/rfc822"
// ],
// "maxSize": "35MB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/email/v2/users/{userKey}/mail"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/email/v2/users/{userKey}/mail"
// }
// }
// },
// "parameterOrder": [
// "userKey"
// ],
// "parameters": {
// "userKey": {
// "description": "The email or immutable id of the user",
// "location": "path",
// "required": true,
//.........这里部分代码省略.........
开发者ID:MarkBruns,项目名称:BeMoreFit,代码行数:101,代码来源:admin-gen.go
示例5: Do
func (c *FilesUpdateCall) Do() (*File, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
if err != nil {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["newRevision"]; ok {
params.Set("newRevision", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateModifiedDate"]; ok {
params.Set("updateModifiedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateViewedDate"]; ok {
params.Set("updateViewedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
if c.media_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", "multipart")
}
urls += "?" + params.Encode()
contentLength_, hasMedia_ := googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
req, _ := http.NewRequest("PUT", urls, body)
googleapi.Expand(req.URL, map[string]string{
"id": c.id,
})
if hasMedia_ {
req.ContentLength = contentLength_
}
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", "google-api-go-client/0.5")
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *File
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Updates file metadata and/or content",
// "httpMethod": "PUT",
// "id": "drive.files.update",
// "mediaUpload": {
// "accept": [
// "*/*"
// ],
// "maxSize": "5120GB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/drive/v1/files/{id}"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/drive/v1/files/{id}"
// }
// }
// },
// "parameterOrder": [
// "id"
// ],
// "parameters": {
// "id": {
// "description": "The id for the file in question.",
// "location": "path",
// "required": true,
// "type": "string"
// },
// "newRevision": {
// "default": "true",
// "description": "Whether a blob upload should create a new revision. If false, the blob data in the current head revision is replaced. If true or not set, a new blob is created as head revision, and previous revisions are preserved (causing increased use of the user's data storage quota).",
// "location": "query",
// "type": "boolean"
// },
// "updateModifiedDate": {
// "default": "false",
// "description": "Controls updating the modified date of the file. If true, the modified date will be updated to the current time, regardless of whether other changes are being made. If false, the modified date will only be updated to the current time if other changes are also being made (changing the title, for example).",
// "location": "query",
// "type": "boolean"
// },
// "updateViewedDate": {
// "default": "true",
// "description": "Whether to update the view date after successfully updating the file.",
// "location": "query",
// "type": "boolean"
// }
// },
// "path": "files/{id}",
//.........这里部分代码省略.........
开发者ID:Tecsisa,项目名称:dex,代码行数:101,代码来源:drive-gen.go
示例6: Do
func (c *FilesInsertCall) Do() (*File, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
if err != nil {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files")
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.SetOpaque(req.URL)
if c.protocol_ == "resumable" {
req.ContentLength = 0
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Body = nil
if params.Get("name") == "" {
return nil, fmt.Errorf("resumable uploads must set the Name parameter.")
}
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", "google-api-go-client/0.5")
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Client: c.s.client,
URI: loc,
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
return nil, err
}
defer res.Body.Close()
}
var ret *File
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Inserts a file, and any settable metadata or blob content sent with the request.",
// "httpMethod": "POST",
// "id": "drive.files.insert",
// "mediaUpload": {
// "accept": [
// "*/*"
// ],
// "maxSize": "5120GB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/drive/v1/files"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/drive/v1/files"
// }
// }
// },
// "path": "files",
// "request": {
// "$ref": "File"
// },
//.........这里部分代码省略.........
开发者ID:avinash-,项目名称:google-api-go-client,代码行数:101,代码来源:drive-gen.go
示例7: Do
func (c *MailInsertCall) Do() error {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.mailitem)
if err != nil {
return err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "{userKey}/mail")
if c.media_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", "multipart")
}
urls += "?" + params.Encode()
contentLength_, hasMedia_ := googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"userKey": c.userKey,
})
if hasMedia_ {
req.ContentLength = contentLength_
}
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", "google-api-go-client/0.5")
res, err := c.s.client.Do(req)
if err != nil {
return err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return err
}
return nil
// {
// "description": "Insert Mail into Google's Gmail backends",
// "httpMethod": "POST",
// "id": "emailMigration.mail.insert",
// "mediaUpload": {
// "accept": [
// "message/rfc822"
// ],
// "maxSize": "35MB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/email/v2/users/{userKey}/mail"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/email/v2/users/{userKey}/mail"
// }
// }
// },
// "parameterOrder": [
// "userKey"
// ],
// "parameters": {
// "userKey": {
// "description": "The email or immutable id of the user",
// "location": "path",
// "required": true,
// "type": "string"
// }
// },
// "path": "{userKey}/mail",
// "request": {
// "$ref": "MailItem"
// },
// "scopes": [
// "https://www.googleapis.com/auth/email.migration"
// ],
// "supportsMediaUpload": true
// }
}
开发者ID:GamerockSA,项目名称:dex,代码行数:79,代码来源:admin-gen.go
示例8: Do
func (c *ImageConfigurationsUploadCall) Do() (*ImageConfiguration, error) {
var body io.Reader = nil
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "images/{resourceId}/imageType/{imageType}")
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"resourceId": c.resourceId,
"imageType": c.imageType,
})
if c.protocol_ == "resumable" {
req.ContentLength = 0
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Body = nil
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Client: c.s.client,
UserAgent: c.s.userAgent(),
URI: loc,
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
return nil, err
}
defer res.Body.Close()
}
var ret *ImageConfiguration
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Uploads an image for a resource with the given ID and image type.",
// "httpMethod": "POST",
// "id": "gamesConfiguration.imageConfigurations.upload",
// "mediaUpload": {
// "accept": [
// "image/*"
// ],
// "maxSize": "15MB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/games/v1configuration/images/{resourceId}/imageType/{imageType}"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/games/v1configuration/images/{resourceId}/imageType/{imageType}"
// }
// }
// },
// "parameterOrder": [
// "resourceId",
// "imageType"
// ],
// "parameters": {
// "imageType": {
//.........这里部分代码省略.........
开发者ID:MarkBruns,项目名称:BeMoreFit,代码行数:101,代码来源:gamesconfiguration-gen.go
示例9: Do
func (c *ArchiveInsertCall) Do() (*Groups, error) {
var body io.Reader = nil
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "{groupId}/archive")
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"groupId": c.groupId,
})
if c.protocol_ == "resumable" {
req.ContentLength = 0
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Body = nil
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Client: c.s.client,
UserAgent: c.s.userAgent(),
URI: loc,
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
return nil, err
}
defer res.Body.Close()
}
var ret *Groups
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Inserts a new mail into the archive of the Google group.",
// "httpMethod": "POST",
// "id": "groupsmigration.archive.insert",
// "mediaUpload": {
// "accept": [
// "message/rfc822"
// ],
// "maxSize": "16MB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/groups/v1/groups/{groupId}/archive"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/groups/v1/groups/{groupId}/archive"
// }
// }
// },
// "parameterOrder": [
// "groupId"
// ],
// "parameters": {
// "groupId": {
// "description": "The group ID",
// "location": "path",
//.........这里部分代码省略.........
开发者ID:MarkBruns,项目名称:BeMoreFit,代码行数:101,代码来源:groupsmigration-gen.go
示例10: Do
func (c *FilesUpdateCall) Do() (*File, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.file)
if err != nil {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["newRevision"]; ok {
params.Set("newRevision", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateModifiedDate"]; ok {
params.Set("updateModifiedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["updateViewedDate"]; ok {
params.Set("updateViewedDate", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "files/{id}")
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
if cancel != nil {
defer cancel()
}
}
req, _ := http.NewRequest("PUT", urls, body)
googleapi.Expand(req.URL, map[string]string{
"id": c.id,
})
if c.protocol_ == "resumable" {
req.ContentLength = 0
if c.mediaType_ == "" {
c.mediaType_ = googleapi.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
req.Body = nil
} else {
req.Header.Set("Content-Type", ctype)
}
req.Header.Set("User-Agent", c.s.userAgent())
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Client: c.s.client,
UserAgent: c.s.userAgent(),
URI: loc,
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
return nil, err
}
defer res.Body.Close()
}
var ret *File
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Updates file metadata and/or content",
// "httpMethod": "PUT",
// "id": "drive.files.update",
// "mediaUpload": {
// "accept": [
// "*/*"
// ],
// "maxSize": "5120GB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/drive/v1/files/{id}"
// },
// "simple": {
//.........这里部分代码省略.........
开发者ID:MarkBruns,项目名称:BeMoreFit,代码行数:101,代码来源:drive-gen.go
示例11: Do
func (c *ArchiveInsertCall) Do() (*Groups, error) {
var body io.Reader = nil
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "{groupId}/archive")
if c.media_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", "multipart")
}
urls += "?" + params.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
contentLength_, hasMedia_ := googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"groupId": c.groupId,
})
if hasMedia_ {
req.ContentLength = contentLength_
}
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", "google-api-go-client/0.5")
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *Groups
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Inserts a new mail into the archive of the Google group.",
// "httpMethod": "POST",
// "id": "groupsmigration.archive.insert",
// "mediaUpload": {
// "accept": [
// "message/rfc822"
// ],
// "maxSize": "16MB",
// "protocols": {
// "resumable": {
// "multipart": true,
// "path": "/resumable/upload/groups/v1/groups/{groupId}/archive"
// },
// "simple": {
// "multipart": true,
// "path": "/upload/groups/v1/groups/{groupId}/archive"
// }
// }
// },
// "parameterOrder": [
// "groupId"
// ],
// "parameters": {
// "groupId": {
// "description": "The group ID",
// "location": "path",
// "required": true,
// "type": "string"
// }
// },
// "path": "{groupId}/archive",
// "response": {
// "$ref": "Groups"
// },
// "supportsMediaUpload": true
// }
}
开发者ID:GamerockSA,项目名称:dex,代码行数:77,代码来源:groupsmigration-gen.go
注:本文中的google/golang.org/api/googleapi.ConditionallyIncludeMedia函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论