Skip to content

Commit

Permalink
Improved flow by defining httpClient only once
Browse files Browse the repository at this point in the history
Signed-off-by: Tim de Pater <[email protected]>
  • Loading branch information
TrafeX committed Jul 27, 2021
1 parent 3acda51 commit 41e0f4e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,27 @@ func main() {
// returns nil if not provided and falls back to simple TCP.
tlsConfig := createTLSConfig(*esCA, *esClientCert, *esClientPrivateKey, *esInsecureSkipVerify)

httpTransport := &http.Transport{
var httpTransport http.RoundTripper

httpTransport = &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
}

httpClient := &http.Client{
Timeout: *esTimeout,
Transport: httpTransport,
}

if *esApiKey != "" {
apiKey := *esApiKey
httpClient = &http.Client{
Timeout: *esTimeout,
Transport: &transportWithApiKey{
underlyingTransport: httpTransport,
apiKey: apiKey,
},

httpTransport = &transportWithApiKey{
underlyingTransport: httpTransport,
apiKey: apiKey,
}
}

httpClient := &http.Client{
Timeout: *esTimeout,
Transport: httpTransport,
}

// version metric
versionMetric := version.NewCollector(Name)
prometheus.MustRegister(versionMetric)
Expand Down

0 comments on commit 41e0f4e

Please sign in to comment.