Jelajahi Sumber

lazy init of dialer map

Darien Raymond 7 tahun lalu
induk
melakukan
169b901c2d
1 mengubah file dengan 5 tambahan dan 1 penghapusan
  1. 5 1
      transport/internet/http/dialer.go

+ 5 - 1
transport/internet/http/dialer.go

@@ -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
 	}