Work around golang.org/issue/4590

Change-Id: Ibde7a93db7dcb8c51eb828b6c4e50505904fce6a
This commit is contained in:
Brad Fitzpatrick 2012-12-26 13:36:45 -08:00
parent a2df86d08e
commit 764e41a50c
1 changed files with 5 additions and 2 deletions

View File

@ -145,15 +145,18 @@ func (c *Client) SearchExistingFileSchema(wholeRef *blobref.BlobRef) (*blobref.B
}
var buf bytes.Buffer
body := io.TeeReader(io.LimitReader(res.Body, 1<<20), &buf)
type justWriter struct {
io.Writer
}
if res.StatusCode != 200 {
io.Copy(struct{ io.Writer }{ioutil.Discard}, body) // golang.org/issue/4589
io.Copy(justWriter{ioutil.Discard}, body) // golang.org/issue/4589
return nil, fmt.Errorf("client: got status code %d from URL %s; body %s", res.StatusCode, url, buf.String())
}
var ress struct {
Files []*blobref.BlobRef `json:"files"`
}
if err := json.NewDecoder(body).Decode(&ress); err != nil {
io.Copy(struct{ io.Writer }{ioutil.Discard}, body) // golang.org/issue/4589
io.Copy(justWriter{ioutil.Discard}, body) // golang.org/issue/4589
return nil, fmt.Errorf("client: error parsing JSON from URL %s: %v; body=%s", url, err, buf.String())
}
if len(ress.Files) == 0 {