From 7a8bc2e19ea7d79a3c80e954dadf8847a0851773 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 12 Mar 2014 15:17:23 -0700 Subject: [PATCH] avoid sharing same err variable --- go/operation/upload_content.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/go/operation/upload_content.go b/go/operation/upload_content.go index 7d88b3721..10e9db315 100644 --- a/go/operation/upload_content.go +++ b/go/operation/upload_content.go @@ -53,35 +53,35 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error if isGzipped { h.Set("Content-Encoding", "gzip") } - file_writer, err := body_writer.CreatePart(h) - if err != nil { - glog.V(0).Infoln("error creating form file", err) - return nil, err + file_writer, cp_err := body_writer.CreatePart(h) + if cp_err != nil { + glog.V(0).Infoln("error creating form file", cp_err.Error()) + return nil, cp_err } - if err = fillBufferFunction(file_writer); err != nil { + if err := fillBufferFunction(file_writer); err != nil { glog.V(0).Infoln("error copying data", err) return nil, err } content_type := body_writer.FormDataContentType() - if err = body_writer.Close(); err != nil { + if err := body_writer.Close(); err != nil { glog.V(0).Infoln("error closing body", err) return nil, err } - resp, err := client.Post(uploadUrl, content_type, body_buf) - if err != nil { - glog.V(0).Infoln("failing to upload to", uploadUrl, err.Error()) - return nil, err + resp, post_err := client.Post(uploadUrl, content_type, body_buf) + if post_err != nil { + glog.V(0).Infoln("failing to upload to", uploadUrl, post_err.Error()) + return nil, post_err } defer resp.Body.Close() - resp_body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err + resp_body, ra_err := ioutil.ReadAll(resp.Body) + if ra_err != nil { + return nil, ra_err } var ret UploadResult - err = json.Unmarshal(resp_body, &ret) - if err != nil { + unmarshal_err := json.Unmarshal(resp_body, &ret) + if unmarshal_err != nil { glog.V(0).Infoln("failing to read upload resonse", uploadUrl, string(resp_body)) - return nil, err + return nil, unmarshal_err } if ret.Error != "" { return nil, errors.New(ret.Error)