Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardovivanco committed May 9, 2024
1 parent c8e3f48 commit 93970ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions http_client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type httpClientWrapper struct {
baseURL string
headers map[string]string
torProxyURL string
retry int
retry uint
}

type HTTPResponseError struct {
Expand All @@ -32,7 +32,7 @@ func BuildResponseError(statusCode int, err error) error {
return HTTPResponseError{StatusCode: statusCode, error: err}
}

func NewHTTPClientWrapper(baseURL, torProxyURL string, timeout time.Duration, headers map[string]string, addJSONHeaders bool, opts ...HttpClientWrapperOption) (HTTPClientWrapper, error) {
func NewHTTPClientWrapper(baseURL, torProxyURL string, timeout time.Duration, headers map[string]string, addJSONHeaders bool, opts ...HTTPClientWrapperOption) (HTTPClientWrapper, error) {
if headers == nil {
headers = map[string]string{}
}
Expand All @@ -51,7 +51,7 @@ func NewHTTPClientWrapper(baseURL, torProxyURL string, timeout time.Duration, he
client.Transport = &http.Transport{Proxy: http.ProxyURL(proxyURL)}
}

params := defaultHttpClientWrapperOptions
params := defaultHTTPClientWrapperOptions
for _, opt := range opts {
opt(&params)
}
Expand All @@ -65,19 +65,23 @@ func NewHTTPClientWrapper(baseURL, torProxyURL string, timeout time.Duration, he
}, nil
}

type HttpClientWrapperOptions struct {
Retry int
type HTTPClientWrapperOptions struct {
Retry uint
}

var defaultHttpClientWrapperOptions = HttpClientWrapperOptions{
var defaultHTTPClientWrapperOptions = HTTPClientWrapperOptions{
Retry: 5,
}

type HttpClientWrapperOption func(*HttpClientWrapperOptions)
type HTTPClientWrapperOption func(*HTTPClientWrapperOptions)

func WithRetry(retry int) HttpClientWrapperOption {
return func(opts *HttpClientWrapperOptions) {
opts.Retry = retry
func WithRetry(retry uint) HTTPClientWrapperOption {
return func(opts *HTTPClientWrapperOptions) {
if retry >= 0 {

Check failure on line 80 in http_client_wrapper.go

View workflow job for this annotation

GitHub Actions / lint

SA4003: every value of type uint is >= 0 (staticcheck)
opts.Retry = retry
} else {
opts.Retry = defaultHTTPClientWrapperOptions.Retry
}
}
}

Expand Down Expand Up @@ -113,7 +117,7 @@ func (h httpClientWrapper) ExecuteRequest(path, method string, body []byte) (*ht
return errResp
}
return err
}, retry.Attempts(uint(h.retry)), retry.Delay(500*time.Millisecond), retry.MaxDelay(9*time.Second))
}, retry.Attempts(h.retry), retry.Delay(500*time.Millisecond), retry.MaxDelay(9*time.Second))

if res == nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions http_client_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func Test_httpClientWrapper_ExecuteRequest_failsTooManyRetries(t *testing.T) {
const baseURL = "http://test.com"
retryCount := 5
retryCount := uint(5)

hcw, _ := NewHTTPClientWrapper(baseURL, "", 1, nil, true, WithRetry(retryCount))
httpmock.Activate()
Expand All @@ -21,7 +21,7 @@ func Test_httpClientWrapper_ExecuteRequest_failsTooManyRetries(t *testing.T) {
countInfo := httpmock.GetCallCountInfo()
c := countInfo["GET "+baseURL+path]

assert.Equal(t, retryCount, c, "expected five retries")
assert.Equal(t, int(retryCount), c, "expected five retries")
assert.Error(t, err, "expected error")
assert.ErrorIs(t, err, err.(HTTPResponseError), "expected HTTPResponseError")
assert.Equal(t, 503, err.(HTTPResponseError).StatusCode, "expected 409")
Expand Down

0 comments on commit 93970ab

Please sign in to comment.