本文整理汇总了Golang中google/golang.org/api/gensupport.CombineBodyMedia函数的典型用法代码示例。如果您正苦于以下问题:Golang CombineBodyMedia函数的具体用法?Golang CombineBodyMedia怎么用?Golang CombineBodyMedia使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CombineBodyMedia函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doRequest
func (c *ArchiveInsertCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
c.urlParams_.Set("alt", alt)
urls := googleapi.ResolveRelative(c.s.BasePath, "{groupId}/archive")
if c.media_ != nil || c.resumableBuffer_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
protocol := "multipart"
if c.resumableBuffer_ != nil {
protocol = "resumable"
}
c.urlParams_.Set("uploadType", protocol)
}
urls += "?" + c.urlParams_.Encode()
body = new(bytes.Buffer)
ctype := "application/json"
if c.media_ != nil {
var combined io.ReadCloser
combined, ctype = gensupport.CombineBodyMedia(body, ctype, c.media_, c.mediaType_)
defer combined.Close()
body = combined
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"groupId": c.groupId,
})
if c.resumableBuffer_ != nil {
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
}
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)
}
示例2: doRequest
func (c *FilesInsertCall) 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"
c.urlParams_.Set("alt", alt)
urls := googleapi.ResolveRelative(c.s.BasePath, "files")
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" && c.media_ != nil {
var combined io.ReadCloser
combined, ctype = gensupport.CombineBodyMedia(body, ctype, c.media_, c.mediaType_)
defer combined.Close()
body = combined
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.SetOpaque(req.URL)
if c.protocol_ == "resumable" {
if c.resumableMediaType_ == "" {
c.resumableMediaType_ = gensupport.DetectMediaType(c.resumable_)
}
req.Header.Set("X-Upload-Content-Type", c.resumableMediaType_)
}
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)
}
示例3: doRequest
func (c *MediaUploadCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.media)
if err != nil {
return nil, err
}
ctype := "application/json"
c.urlParams_.Set("alt", alt)
urls := googleapi.ResolveRelative(c.s.BasePath, "v1/media/{+resourceName}")
if c.media_ != nil || c.resumableBuffer_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
protocol := "multipart"
if c.resumableBuffer_ != nil {
protocol = "resumable"
}
c.urlParams_.Set("uploadType", protocol)
}
urls += "?" + c.urlParams_.Encode()
if c.media_ != nil {
var combined io.ReadCloser
combined, ctype = gensupport.CombineBodyMedia(body, ctype, c.media_, c.mediaType_)
defer combined.Close()
body = combined
}
req, _ := http.NewRequest("POST", urls, body)
googleapi.Expand(req.URL, map[string]string{
"resourceName": c.resourceName,
})
if c.resumableBuffer_ != nil {
req.Header.Set("X-Upload-Content-Type", c.mediaType_)
}
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)
}
示例4: doRequest
func (c *ArchiveInsertCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := make(http.Header)
for k, v := range c.header_ {
reqHeaders[k] = v
}
reqHeaders.Set("User-Agent", c.s.userAgent())
var body io.Reader = nil
c.urlParams_.Set("alt", alt)
urls := googleapi.ResolveRelative(c.s.BasePath, "{groupId}/archive")
if c.media_ != nil || c.mediaBuffer_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
protocol := "multipart"
if c.mediaBuffer_ != nil {
protocol = "resumable"
}
c.urlParams_.Set("uploadType", protocol)
}
if body == nil {
body = new(bytes.Buffer)
reqHeaders.Set("Content-Type", "application/json")
}
if c.media_ != nil {
combined, ctype := gensupport.CombineBodyMedia(body, "application/json", c.media_, c.mediaType_)
defer combined.Close()
reqHeaders.Set("Content-Type", ctype)
body = combined
}
if c.mediaBuffer_ != nil && c.mediaType_ != "" {
reqHeaders.Set("X-Upload-Content-Type", c.mediaType_)
}
urls += "?" + c.urlParams_.Encode()
req, _ := http.NewRequest("POST", urls, body)
req.Header = reqHeaders
googleapi.Expand(req.URL, map[string]string{
"groupId": c.groupId,
})
return gensupport.SendRequest(c.ctx_, c.s.client, req)
}