Skip to content

Commit 3acda51

Browse files
committed
No need to keep a reference to the apikey and use sprintf for concatenation
Signed-off-by: Tim de Pater <[email protected]>
1 parent 0723e2c commit 3acda51

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

main.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package main
1515

1616
import (
17+
"fmt"
1718
"net/http"
1819
"net/url"
1920
"os"
@@ -33,11 +34,11 @@ import (
3334

3435
type transportWithApiKey struct {
3536
underlyingTransport http.RoundTripper
36-
apiKey *string
37+
apiKey string
3738
}
3839

3940
func (t *transportWithApiKey) RoundTrip(req *http.Request) (*http.Response, error) {
40-
req.Header.Add("Authorization", "ApiKey "+*t.apiKey)
41+
req.Header.Add("Authorization", fmt.Sprintf("ApiKey %s", t.apiKey))
4142
return t.underlyingTransport.RoundTrip(req)
4243
}
4344

@@ -138,11 +139,12 @@ func main() {
138139
}
139140

140141
if *esApiKey != "" {
142+
apiKey := *esApiKey
141143
httpClient = &http.Client{
142144
Timeout: *esTimeout,
143145
Transport: &transportWithApiKey{
144146
underlyingTransport: httpTransport,
145-
apiKey: esApiKey,
147+
apiKey: apiKey,
146148
},
147149
}
148150
}

0 commit comments

Comments
 (0)