From 98d073975358b86a628fec857656302f6322ce28 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 17 Jul 2011 13:11:53 -0700 Subject: [PATCH] fixes to go-flickr to make it compile with recent Go Change-Id: I95e9c0ad7ca948022ae083a06f6f8e082f62d376 --- .last_go_version | 2 +- .../github.com/mncaudill/go-flickr/flickr.go | 48 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.last_go_version b/.last_go_version index 1d7582d97..a8ed99b63 100644 --- a/.last_go_version +++ b/.last_go_version @@ -1 +1 @@ -6g version weekly.2011-07-07 9081 +6g version weekly.2011-07-07 9132+ diff --git a/lib/go/camli/third_party/github.com/mncaudill/go-flickr/flickr.go b/lib/go/camli/third_party/github.com/mncaudill/go-flickr/flickr.go index e191379b3..b8fa10aff 100644 --- a/lib/go/camli/third_party/github.com/mncaudill/go-flickr/flickr.go +++ b/lib/go/camli/third_party/github.com/mncaudill/go-flickr/flickr.go @@ -1,16 +1,14 @@ package flickr import ( - "io" - "os" - "fmt" - "net" - "http" - "sort" - "bufio" "bytes" - "io/ioutil" "crypto/md5" + "fmt" + "http" + "io" + "io/ioutil" + "os" + "sort" ) const ( @@ -24,6 +22,7 @@ type Request struct { ApiKey string Method string Args map[string]string + Client *http.Client // if nil, http.DefaultClient is used } type nopCloser struct { @@ -55,7 +54,7 @@ func (request *Request) Sign(secret string) { sorted_keys[i] = k i++ } - sort.SortStrings(sorted_keys) + sort.Strings(sorted_keys) // Build out ordered key-value string prefixed by secret s := secret @@ -96,7 +95,7 @@ func (request *Request) Execute() (response string, ret os.Error) { s := request.URL() - res, _, err := http.Get(s) + res, err := http.Get(s) defer res.Body.Close() if err != nil { return "", err @@ -187,7 +186,7 @@ func (request *Request) Upload(filename string, filetype string) (response strin return "", err } - return sendPost(postRequest) + return request.sendPost(postRequest) } func (request *Request) Replace(filename string, filetype string) (response string, err os.Error) { @@ -195,25 +194,24 @@ func (request *Request) Replace(filename string, filetype string) (response stri if err != nil { return "", err } - return sendPost(postRequest) + return request.sendPost(postRequest) } -func sendPost(postRequest *http.Request) (body string, err os.Error) { - // Create and use TCP connection (lifted mostly wholesale from http.send) - conn, err := net.Dial("tcp", "api.flickr.com:80") - defer conn.Close() - - if err != nil { - return "", err +func (r *Request) client() *http.Client { + if r.Client != nil { + return r.Client } - postRequest.Write(conn) + return http.DefaultClient +} - reader := bufio.NewReader(conn) - resp, err := http.ReadResponse(reader, postRequest.Method) +func (r *Request) sendPost(post *http.Request) (body string, err os.Error) { + resp, err := r.client().Do(post) if err != nil { - return "", err + return } - rawBody, _ := ioutil.ReadAll(resp.Body) - + rawBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + return + } return string(rawBody), nil }