Skip to content

Commit ac774e4

Browse files
Fix: DefaultClient to custom
1 parent 574cc6c commit ac774e4

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

hasura/api.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"net/url"
88
"path"
9+
"time"
910

1011
jsoniter "github.com/json-iterator/go"
1112

@@ -19,12 +20,20 @@ type API struct {
1920
baseURL string
2021
secret string
2122

22-
client http.Client
23+
client *http.Client
2324
}
2425

2526
// New -
2627
func New(baseURL, secret string) *API {
27-
return &API{baseURL, secret, *http.DefaultClient}
28+
t := http.DefaultTransport.(*http.Transport).Clone()
29+
t.MaxIdleConns = 100
30+
t.MaxConnsPerHost = 100
31+
t.MaxIdleConnsPerHost = 100
32+
33+
return &API{baseURL, secret, &http.Client{
34+
Timeout: time.Minute,
35+
Transport: t,
36+
}}
2837
}
2938

3039
func (api *API) buildURL(endpoint string, args map[string]string) (string, error) {

node/node.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"path"
1111
"strings"
12+
"time"
1213

1314
jsoniter "github.com/json-iterator/go"
1415
"github.com/pkg/errors"
@@ -19,12 +20,22 @@ var json = jsoniter.ConfigCompatibleWithStandardLibrary
1920
// NodeRPC -
2021
type NodeRPC struct {
2122
baseURL string
23+
client *http.Client
2224
}
2325

2426
// NewNodeRPC -
2527
func NewNodeRPC(baseURL string) *NodeRPC {
28+
t := http.DefaultTransport.(*http.Transport).Clone()
29+
t.MaxIdleConns = 100
30+
t.MaxConnsPerHost = 100
31+
t.MaxIdleConnsPerHost = 100
32+
2633
return &NodeRPC{
2734
baseURL: strings.TrimSuffix(baseURL, "/"),
35+
client: &http.Client{
36+
Timeout: time.Second * 15,
37+
Transport: t,
38+
},
2839
}
2940
}
3041

@@ -75,7 +86,7 @@ func (rpc *NodeRPC) makeRequest(method, uri string, queryArgs url.Values, body i
7586
if err != nil {
7687
return nil, errors.Errorf("makeGetRequest.NewRequest: %v", err)
7788
}
78-
return http.DefaultClient.Do(req)
89+
return rpc.client.Do(req)
7990
}
8091

8192
//nolint

tzkt/api/api.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"path"
1111
"strconv"
12+
"time"
1213

1314
jsoniter "github.com/json-iterator/go"
1415
"github.com/pkg/errors"
@@ -24,9 +25,17 @@ type API struct {
2425

2526
// New -
2627
func New(baseURL string) *API {
28+
t := http.DefaultTransport.(*http.Transport).Clone()
29+
t.MaxIdleConns = 100
30+
t.MaxConnsPerHost = 100
31+
t.MaxIdleConnsPerHost = 100
32+
2733
return &API{
28-
url: baseURL,
29-
client: http.DefaultClient,
34+
url: baseURL,
35+
client: &http.Client{
36+
Timeout: time.Minute,
37+
Transport: t,
38+
},
3039
}
3140
}
3241

tzkt/events/signalr/transport.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package signalr
33
import (
44
"net/http"
55
"net/url"
6+
"time"
67

78
"github.com/rs/zerolog/log"
89

@@ -20,13 +21,23 @@ const (
2021

2122
// Transport -
2223
type Transport struct {
23-
url string
24+
url string
25+
client *http.Client
2426
}
2527

2628
// NewTransport -
2729
func NewTransport(baseURL string) *Transport {
30+
t := http.DefaultTransport.(*http.Transport).Clone()
31+
t.MaxIdleConns = 100
32+
t.MaxConnsPerHost = 100
33+
t.MaxIdleConnsPerHost = 100
34+
2835
return &Transport{
2936
url: baseURL,
37+
client: &http.Client{
38+
Timeout: time.Minute,
39+
Transport: t,
40+
},
3041
}
3142
}
3243

@@ -48,7 +59,7 @@ func (t *Transport) Negotiate(version Version) (response NegotiateResponse, err
4859
return
4960
}
5061

51-
resp, err := http.DefaultClient.Do(req)
62+
resp, err := t.client.Do(req)
5263
if err != nil {
5364
return
5465
}

0 commit comments

Comments
 (0)