Skip to content

Commit 3ba9982

Browse files
committed
Implement ConnectTimeout and stub out Timeout
1 parent 49a64b7 commit 3ba9982

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

notes.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
Notes on Go Swift
22
=================
33

4-
Test that time works if pc timezone is not GMT
5-
64
Make a container struct so these could be methods on it?
75

8-
// FIXME make noResponse check for 204?
6+
Make noResponse check for 204?
97

108
Make storage public so it can be extended easily?
119

@@ -46,7 +44,4 @@ Copy/Rename object
4644

4745
Swift client retries and backs off for all types of errors
4846

49-
Write a script which uses this and replicates the functionality of swift tool
50-
51-
path parameter is missing in the docs for Objects() but supported by the server
52-
is it deprecated? or are the docs faults?
47+
Make Timeout work as well as ConnectionTimeout

swift.go

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"io"
1212
"log"
13+
"net"
1314
"net/http"
1415
"net/url"
1516
"strconv"
@@ -34,15 +35,17 @@ const (
3435
// Rackspace UK https://lon.auth.api.rackspacecloud.com/v1.0
3536
// Memset Memstore UK https://auth.storage.memset.com/v1.0
3637
type Connection struct {
37-
UserName string // UserName for api
38-
ApiKey string // Key for api access
39-
AuthUrl string // Auth URL
40-
Retries int // Retries on error (default is 3)
41-
UserAgent string // Http User agent (default goswift/1.0)
42-
storageUrl string
43-
authToken string
44-
tr *http.Transport
45-
client *http.Client
38+
UserName string // UserName for api
39+
ApiKey string // Key for api access
40+
AuthUrl string // Auth URL
41+
Retries int // Retries on error (default is 3)
42+
UserAgent string // Http User agent (default goswift/1.0)
43+
ConnectTimeout time.Duration // Connect channel timeout (default 10s)
44+
Timeout time.Duration // Data channel timeout (default 60s) NOT IMPLEMENTED
45+
storageUrl string
46+
authToken string
47+
tr *http.Transport
48+
client *http.Client
4649
}
4750

4851
// Error - all errors generated by this package are of this type. Other error
@@ -149,10 +152,31 @@ func (c *Connection) Authenticate() (err error) {
149152
if c.Retries == 0 {
150153
c.Retries = DefaultRetries
151154
}
155+
if c.ConnectTimeout == 0 {
156+
c.ConnectTimeout = 10 * time.Second
157+
}
158+
if c.Timeout == 0 {
159+
c.Timeout = 60 * time.Second
160+
}
152161
if c.tr == nil {
153162
c.tr = &http.Transport{
154-
// TLSClientConfig: &tls.Config{RootCAs: pool},
155-
// DisableCompression: true,
163+
// TLSClientConfig: &tls.Config{RootCAs: pool},
164+
// DisableCompression: true,
165+
166+
// Dial with deadline
167+
//
168+
// FIXME not sure how this plays with connection pooling
169+
Dial: func(network, addr string) (net.Conn, error) {
170+
conn, err := net.DialTimeout(network, addr, c.ConnectTimeout)
171+
if err != nil {
172+
return nil, err
173+
}
174+
// FIXME Need to continuously bump this
175+
// deadline forwards but can't figure
176+
// out how to get the net.Conn out of the Request
177+
// conn.SetDeadline(time.Now().Add(c.Timeout))
178+
return conn, nil
179+
},
156180
}
157181
}
158182
if c.client == nil {

0 commit comments

Comments
 (0)