func (c *APIClient) post(m apiMethod, body []byte) ([]byte, error) {
	req, _ := http.NewRequest("POST", m.url(), bytes.NewReader(body))
	googleapi.SetOpaque(req.URL)
	resp, err := c.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if err := googleapi.CheckResponse(resp); err != nil {
		return nil, err
	}
	return ioutil.ReadAll(resp.Body)
}
Beispiel #2
0
func getObjectContents(o *storage.Object) ([]byte, error) {
	urls := "https://www.googleapis.com/download/storage/v1/b/{BUCKET}/o/{OBJECT}?alt=media"

	req, _ := http.NewRequest("GET", urls, nil)
	req.URL.Path = strings.Replace(req.URL.Path, "{BUCKET}", url.QueryEscape(o.Bucket), 1)
	req.URL.Path = strings.Replace(req.URL.Path, "{OBJECT}", url.QueryEscape(o.Name), 1)
	googleapi.SetOpaque(req.URL)

	r, err := c.Do(req)
	if err != nil {
		return nil, err
	}
	defer r.Body.Close()
	contents, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return nil, err
	}
	return contents, nil
}