Fix more golint warnings.
[arvados.git] / sdk / go / keepclient / keepclient.go
index 6a3e83796ed9fb7d9a91fdaff1bcab625d0ad909..8eff377ce651513cc6170848d18ea25cd260d5fb 100644 (file)
@@ -20,9 +20,9 @@ import (
        "sync"
        "time"
 
-       "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
-       "git.curoverse.com/arvados.git/sdk/go/asyncbuf"
-       "git.curoverse.com/arvados.git/sdk/go/httpserver"
+       "git.arvados.org/arvados.git/sdk/go/arvadosclient"
+       "git.arvados.org/arvados.git/sdk/go/asyncbuf"
+       "git.arvados.org/arvados.git/sdk/go/httpserver"
 )
 
 // A Keep "block" is 64MB.
@@ -290,10 +290,9 @@ func (kc *KeepClient) getOrHead(method string, locator string, header http.Heade
                                        Hash:   md5.New(),
                                        Check:  locator[0:32],
                                }, expectLength, url, resp.Header, nil
-                       } else {
-                               resp.Body.Close()
-                               return nil, expectLength, url, resp.Header, nil
                        }
+                       resp.Body.Close()
+                       return nil, expectLength, url, resp.Header, nil
                }
                serversToTry = retryList
        }
@@ -493,9 +492,8 @@ func (kc *KeepClient) getSortedRoots(locator string) []string {
 func (kc *KeepClient) cache() *BlockCache {
        if kc.BlockCache != nil {
                return kc.BlockCache
-       } else {
-               return DefaultBlockCache
        }
+       return DefaultBlockCache
 }
 
 func (kc *KeepClient) ClearBlockCache() {
@@ -546,31 +544,26 @@ func (kc *KeepClient) httpClient() HTTPClient {
                keepAlive = DefaultKeepAlive
        }
 
-       transport, ok := http.DefaultTransport.(*http.Transport)
-       if ok {
-               copy := *transport
-               transport = &copy
-       } else {
-               // Evidently the application has replaced
-               // http.DefaultTransport with a different type, so we
-               // need to build our own from scratch using the Go 1.8
-               // defaults.
-               transport = &http.Transport{
+       c := &http.Client{
+               Timeout: requestTimeout,
+               // It's not safe to copy *http.DefaultTransport
+               // because it has a mutex (which might be locked)
+               // protecting a private map (which might not be nil).
+               // So we build our own, using the Go 1.12 default
+               // values, ignoring any changes the application has
+               // made to http.DefaultTransport.
+               Transport: &http.Transport{
+                       DialContext: (&net.Dialer{
+                               Timeout:   connectTimeout,
+                               KeepAlive: keepAlive,
+                               DualStack: true,
+                       }).DialContext,
                        MaxIdleConns:          100,
                        IdleConnTimeout:       90 * time.Second,
-                       ExpectContinueTimeout: time.Second,
-               }
-       }
-       transport.DialContext = (&net.Dialer{
-               Timeout:   connectTimeout,
-               KeepAlive: keepAlive,
-               DualStack: true,
-       }).DialContext
-       transport.TLSHandshakeTimeout = tlsTimeout
-       transport.TLSClientConfig = arvadosclient.MakeTLSConfig(kc.Arvados.ApiInsecure)
-       c := &http.Client{
-               Timeout:   requestTimeout,
-               Transport: transport,
+                       TLSHandshakeTimeout:   tlsTimeout,
+                       ExpectContinueTimeout: 1 * time.Second,
+                       TLSClientConfig:       arvadosclient.MakeTLSConfig(kc.Arvados.ApiInsecure),
+               },
        }
        defaultClient[kc.Arvados.ApiInsecure][kc.foundNonDiskSvc] = c
        return c
@@ -581,9 +574,8 @@ var reqIDGen = httpserver.IDGenerator{Prefix: "req-"}
 func (kc *KeepClient) getRequestID() string {
        if kc.RequestID != "" {
                return kc.RequestID
-       } else {
-               return reqIDGen.Next()
        }
+       return reqIDGen.Next()
 }
 
 type Locator struct {