@@ -13,20 +13,32 @@ import (
1313
1414type publicIPRepoProviders struct {
1515 providers []string
16+ transport * http.Transport
1617}
1718
1819
1920
2021func NewPublicIPRepository () PublicIPRepository {
2122 var providers = []string {"https://api.ipify.org/" ,"http://ifconfig.io/ip" ,"http://ipecho.net/plain" ,"http://icanhazip.com" ,"https://ifconfig.me/ip" ,"https://myexternalip.com/raw" }
23+
2224 dialer := & net.Dialer {
23- Timeout : time .Duration (5 * time .Second ),
25+ Timeout : 10 * time .Second ,
26+ KeepAlive : 10 * time .Second ,
27+ }
28+
29+ var MyTransport = & http.Transport {
30+ DialContext : dialer .DialContext ,
31+ MaxIdleConns : 100 ,
32+ IdleConnTimeout : 90 * time .Second ,
33+ TLSHandshakeTimeout : 10 * time .Second ,
34+ ExpectContinueTimeout : 1 * time .Second ,
2435 }
25- http . DefaultTransport .( * http. Transport ) .DialContext = func (ctx context.Context , _ , addr string ) (net.Conn , error ) {
36+ MyTransport .DialContext = func (ctx context.Context , _ , addr string ) (net.Conn , error ) {
2637 return dialer .DialContext (ctx , "tcp4" , addr )
2738 }
2839 return & publicIPRepoProviders {
2940 providers : providers ,
41+ transport : MyTransport ,
3042 }
3143}
3244
0 commit comments