From aeb98e63bf65a439ac6a0773c630977047cdc8e1 Mon Sep 17 00:00:00 2001 From: Justin Tulloss Date: Sun, 23 Nov 2014 12:57:30 -0800 Subject: [PATCH] Use httpcontrol library to manage timeouts Instead of maintaining that code here, let's just use a library. --- firebase.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/firebase.go b/firebase.go index abcd049..3ca8743 100644 --- a/firebase.go +++ b/firebase.go @@ -7,11 +7,12 @@ import ( "errors" "io/ioutil" "log" - "net" "net/http" "net/url" "strings" "time" + + "github.com/facebookgo/httpcontrol" ) // Api is the interface for interacting with Firebase. @@ -285,21 +286,12 @@ func (f *f) Call(method, path, auth string, body []byte, params map[string]strin return ret, nil } -func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error) { - return func(netw, addr string) (net.Conn, error) { - conn, err := net.DialTimeout(netw, addr, cTimeout) - if err != nil { - return nil, err - } - conn.SetDeadline(time.Now().Add(rwTimeout)) - return conn, nil - } -} - func newTimeoutClient(connectTimeout time.Duration, readWriteTimeout time.Duration) *http.Client { return &http.Client{ - Transport: &http.Transport{ - Dial: TimeoutDialer(connectTimeout, readWriteTimeout), + Transport: &httpcontrol.Transport{ + RequestTimeout: readWriteTimeout, + DialTimeout: connectTimeout, + MaxTries: 3, }, } }