lazy init of dialer map

pull/981/head
Darien Raymond 2018-03-21 23:28:28 +01:00
parent e647292b9a
commit 169b901c2d
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 5 additions and 1 deletions

View File

@ -17,7 +17,7 @@ import (
)
var (
globalDialerMap = make(map[net.Destination]*http.Client)
globalDialerMap map[net.Destination]*http.Client
globalDailerAccess sync.Mutex
)
@ -25,6 +25,10 @@ func getHTTPClient(ctx context.Context, dest net.Destination) (*http.Client, err
globalDailerAccess.Lock()
defer globalDailerAccess.Unlock()
if globalDialerMap == nil {
globalDialerMap = make(map[net.Destination]*http.Client)
}
if client, found := globalDialerMap[dest]; found {
return client, nil
}