Skip to content

Commit

Permalink
chore(client): remove the logger from the default HTTPClient (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 authored Aug 29, 2024
1 parent 1d8d45b commit 13f7be9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions client_options.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tapd

import "net/http"

type ClientOption func(*Client) error

// WithBaseURL sets the baseURL for the client
Expand All @@ -24,3 +26,10 @@ func WithUserAgent(userAgent string) ClientOption {
return nil
}
}

func WithHTTPClient(httpClient *http.Client) ClientOption {
return func(c *Client) error {
c.httpClient = httpClient
return nil
}
}
2 changes: 1 addition & 1 deletion client_options_http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func WithRetryableHTTPClientBackoff(backoff retryablehttp.Backoff) RetryableHTTP

func NewRetryableHTTPClient(opts ...RetryableHTTPClientOption) *http.Client {
retryClient := retryablehttp.NewClient()
// retryClient.Logger = nil // todo: set default logger
retryClient.Logger = nil
for _, opt := range opts {
opt(retryClient)
}
Expand Down
9 changes: 8 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tapd
import (
"context"
"fmt"
"log"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -17,7 +18,13 @@ func createServerClient(t *testing.T, handler http.Handler) (*httptest.Server, *
srv := httptest.NewServer(handler)
t.Cleanup(srv.Close)

client, err := NewClient("tapd-username", "tapd-password", WithBaseURL(srv.URL))
client, err := NewClient(
"tapd-username", "tapd-password",
WithBaseURL(srv.URL),
WithHTTPClient(NewRetryableHTTPClient(
WithRetryableHTTPClientLogger(log.New(os.Stderr, "", log.LstdFlags)),
)),
)
assert.NoError(t, err)

return srv, client
Expand Down

0 comments on commit 13f7be9

Please sign in to comment.