Skip to content

Commit 41e0f4e

Browse files
committed
Improved flow by defining httpClient only once
Signed-off-by: Tim de Pater <[email protected]>
1 parent 3acda51 commit 41e0f4e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

main.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,27 @@ func main() {
128128
// returns nil if not provided and falls back to simple TCP.
129129
tlsConfig := createTLSConfig(*esCA, *esClientCert, *esClientPrivateKey, *esInsecureSkipVerify)
130130

131-
httpTransport := &http.Transport{
131+
var httpTransport http.RoundTripper
132+
133+
httpTransport = &http.Transport{
132134
TLSClientConfig: tlsConfig,
133135
Proxy: http.ProxyFromEnvironment,
134136
}
135137

136-
httpClient := &http.Client{
137-
Timeout: *esTimeout,
138-
Transport: httpTransport,
139-
}
140-
141138
if *esApiKey != "" {
142139
apiKey := *esApiKey
143-
httpClient = &http.Client{
144-
Timeout: *esTimeout,
145-
Transport: &transportWithApiKey{
146-
underlyingTransport: httpTransport,
147-
apiKey: apiKey,
148-
},
140+
141+
httpTransport = &transportWithApiKey{
142+
underlyingTransport: httpTransport,
143+
apiKey: apiKey,
149144
}
150145
}
151146

147+
httpClient := &http.Client{
148+
Timeout: *esTimeout,
149+
Transport: httpTransport,
150+
}
151+
152152
// version metric
153153
versionMetric := version.NewCollector(Name)
154154
prometheus.MustRegister(versionMetric)

0 commit comments

Comments
 (0)