21 msformat205 mscheck 249total 23errors 113warnings 113notes

cert_error_go119.go2

5:1redundant-build-taglegacy +build line is redundant with go:build

cert_error_go119.go:5:1

4//go:build !go1.20
5// +build !go1.20
6
7:9package-commentspackage should have a documentation comment

cert_error_go119.go:7:9

6
7package retryablehttp
8

cert_error_go120.go2

5:1redundant-build-taglegacy +build line is redundant with go:build

cert_error_go120.go:5:1

4//go:build go1.20
5// +build go1.20
6
7:9package-commentspackage should have a documentation comment

cert_error_go120.go:7:9

6
7package retryablehttp
8

client.go108

1:1file-length-limitfile has 939 lines; maximum is 500

client.go:1:1

1// Copyright IBM Corp. 2015, 2025
2// SPDX-License-Identifier: MPL-2.0
1:1formatfile is not formatted

client.go:1:1

1// Copyright IBM Corp. 2015, 2025
2// SPDX-License-Identifier: MPL-2.0
  • Fix (safe): run `strider fmt client.go`
49:2no-package-varpackage variables introduce mutable global state

client.go:49:2

48 // Default retry configuration
49 defaultRetryWaitMin = 1 * time.Second
50 defaultRetryWaitMax = 30 * time.Second
50:2no-package-varpackage variables introduce mutable global state

client.go:50:2

49 defaultRetryWaitMin = 1 * time.Second
50 defaultRetryWaitMax = 30 * time.Second
51 defaultRetryMax = 4
51:2no-package-varpackage variables introduce mutable global state

client.go:51:2

50 defaultRetryWaitMax = 30 * time.Second
51 defaultRetryMax = 4
52
54:2no-package-varpackage variables introduce mutable global state

client.go:54:2

53 // defaultLogger is the logger provided with defaultClient
54 defaultLogger = log.New(os.Stderr, "", log.LstdFlags)
55
58:2no-package-varpackage variables introduce mutable global state

client.go:58:2

57 // a new client. It is purposely private to avoid modifications.
58 defaultClient = NewClient()
59
62:2no-package-varpackage variables introduce mutable global state

client.go:62:2

61 // limit the size we consume to respReadLimit.
62 respReadLimit = int64(4096)
63
62:18redundant-conversionconversion from int64 to the identical type is redundant

client.go:62:18

61 // limit the size we consume to respReadLimit.
62 respReadLimit = int64(4096)
63
66:2no-package-varpackage variables introduce mutable global state

client.go:66:2

65 // This defaults to time.Now. Changes to this should only be done in tests.
66 timeNow = time.Now
67
71:2no-package-varpackage variables introduce mutable global state

client.go:71:2

70 // specifically so we resort to matching on the error string.
71 redirectsErrorRe = regexp.MustCompile(`stopped after \d+ redirects\z`)
72
76:2no-package-varpackage variables introduce mutable global state

client.go:76:2

75 // specifically so we resort to matching on the error string.
76 schemeErrorRe = regexp.MustCompile(`unsupported protocol scheme`)
77
81:2no-package-varpackage variables introduce mutable global state

client.go:81:2

80 // specifically so we resort to matching on the error string.
81 invalidHeaderErrorRe = regexp.MustCompile(`invalid header`)
82
86:2no-package-varpackage variables introduce mutable global state

client.go:86:2

85 // specifically so we resort to matching on the error string.
86 notTrustedErrorRe = regexp.MustCompile(`certificate is not trusted`)
87)
89:1doc-comment-perioddocumentation comment should end with punctuation

client.go:89:1

88
89// ReaderFunc is the type of function that can be given natively to NewRequest
90type ReaderFunc func() (io.Reader, error)
102:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:102:6

101// by the caller out-of-band. Failure to do so will result in a memory leak.
102type ResponseHandlerFunc func(*http.Response) error
103
106:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:106:6

105// for automatically sending the right Content-Length header when possible.
106type LenReader interface {
107 Len() int
125:19exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:125:19

124// with its context changed to ctx. The provided ctx must be non-nil.
125func (r *Request) WithContext(ctx context.Context) *Request {
126 return &Request{
144:19exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:144:19

143// call, or at the same time this request is being used with Client.Do.
144func (r *Request) BodyBytes() ([]byte, error) {
145 if r.body == nil {
163:19exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:163:19

162// It is useful if a new body needs to be set without constructing a new Request.
163func (r *Request) SetBody(rawBody interface{}) error {
164 bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody)
163:35use-anyuse any instead of interface{}

client.go:163:35

162// It is useful if a new body needs to be set without constructing a new Request.
163func (r *Request) SetBody(rawBody interface{}) error {
164 bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody)
193:19exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:193:19

192// The signature matches io.WriterTo interface.
193func (r *Request) WriteTo(w io.Writer) (int64, error) {
194 body, err := r.body()
204:6cognitive-complexityfunction has cognitive complexity 19; maximum is 7

client.go:204:6

203
204func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, error) {
205 var bodyReader ReaderFunc
204:6cyclomatic-complexityfunction complexity is 19; maximum is 10

client.go:204:6

203
204func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, error) {
205 var bodyReader ReaderFunc
204:6function-lengthfunction has 50 statements and 99 lines; maximum is 50 statements or 75 lines

client.go:204:6

203
204func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, error) {
205 var bodyReader ReaderFunc
204:44use-anyuse any instead of interface{}

client.go:204:44

203
204func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, error) {
205 var bodyReader ReaderFunc
220:4discarded-error-resulterror result returned by c.Close is discarded

client.go:220:4

219 if c, ok := tmp.(io.Closer); ok {
220 c.Close()
221 }
223:2identical-switch-branchesswitch repeats a case body

client.go:223:2

222
223 case func() (io.Reader, error):
224 bodyReader = body
233:4discarded-error-resulterror result returned by c.Close is discarded

client.go:233:4

232 if c, ok := tmp.(io.Closer); ok {
233 c.Close()
234 }
304:1doc-comment-perioddocumentation comment should end with punctuation

client.go:304:1

303
304// FromRequest wraps an http.Request in a retryablehttp.Request
305func FromRequest(r *http.Request) (*Request, error) {
315:25import-shadowingidentifier url shadows an imported package

client.go:315:25

314// NewRequest creates a new wrapped request.
315func NewRequest(method, url string, rawBody interface{}) (*Request, error) {
316 return NewRequestWithContext(context.Background(), method, url, rawBody)
315:45use-anyuse any instead of interface{}

client.go:315:45

314// NewRequest creates a new wrapped request.
315func NewRequest(method, url string, rawBody interface{}) (*Request, error) {
316 return NewRequestWithContext(context.Background(), method, url, rawBody)
323:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:323:6

322// obtaining a connection, sending the request, and reading the response headers and body.
323func NewRequestWithContext(ctx context.Context, method, url string, rawBody interface{}) (*Request, error) {
324 httpReq, err := http.NewRequestWithContext(ctx, method, url, nil)
323:57import-shadowingidentifier url shadows an imported package

client.go:323:57

322// obtaining a connection, sending the request, and reading the response headers and body.
323func NewRequestWithContext(ctx context.Context, method, url string, rawBody interface{}) (*Request, error) {
324 httpReq, err := http.NewRequestWithContext(ctx, method, url, nil)
323:77use-anyuse any instead of interface{}

client.go:323:77

322// obtaining a connection, sending the request, and reading the response headers and body.
323func NewRequestWithContext(ctx context.Context, method, url string, rawBody interface{}) (*Request, error) {
324 httpReq, err := http.NewRequestWithContext(ctx, method, url, nil)
341:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

client.go:341:1

340// standard log.Logger.
341type Logger interface {
342 Printf(string, ...interface{})
341:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:341:6

340// standard log.Logger.
341type Logger interface {
342 Printf(string, ...interface{})
342:20use-anyuse any instead of interface{}

client.go:342:20

341type Logger interface {
342 Printf(string, ...interface{})
343}
350:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:350:6

349// interface.
350type LeveledLogger interface {
351 Error(msg string, keysAndValues ...interface{})
351:37use-anyuse any instead of interface{}

client.go:351:37

350type LeveledLogger interface {
351 Error(msg string, keysAndValues ...interface{})
352 Info(msg string, keysAndValues ...interface{})
352:36use-anyuse any instead of interface{}

client.go:352:36

351 Error(msg string, keysAndValues ...interface{})
352 Info(msg string, keysAndValues ...interface{})
353 Debug(msg string, keysAndValues ...interface{})
353:37use-anyuse any instead of interface{}

client.go:353:37

352 Info(msg string, keysAndValues ...interface{})
353 Debug(msg string, keysAndValues ...interface{})
354 Warn(msg string, keysAndValues ...interface{})
354:36use-anyuse any instead of interface{}

client.go:354:36

353 Debug(msg string, keysAndValues ...interface{})
354 Warn(msg string, keysAndValues ...interface{})
355}
363:21exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:363:21

362
363func (h hookLogger) Printf(s string, args ...interface{}) {
364 h.Info(fmt.Sprintf(s, args...))
363:46use-anyuse any instead of interface{}

client.go:363:46

362
363func (h hookLogger) Printf(s string, args ...interface{}) {
364 h.Info(fmt.Sprintf(s, args...))
371:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:371:6

370// consumers.
371type RequestLogHook func(Logger, *http.Request, int)
372
378:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:378:6

377// from this method, this will affect the response returned from Do().
378type ResponseLogHook func(Logger, *http.Response)
379
388:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:388:6

387// response body before returning.
388type CheckRetry func(ctx context.Context, resp *http.Response, err error) (bool, error)
389
393:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:393:6

392// that should pass before trying again.
393type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration
394
393:19redefines-builtin-ididentifier min shadows a predeclared identifier

client.go:393:19

392// that should pass before trying again.
393type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration
394
393:24redefines-builtin-ididentifier max shadows a predeclared identifier

client.go:393:24

392// that should pass before trying again.
393type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration
394
399:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:399:6

398// attempted. If overriding this, be sure to close the body if needed.
399type ErrorHandler func(resp *http.Response, err error, numTries int) (*http.Response, error)
400
401:1doc-comment-perioddocumentation comment should end with punctuation

client.go:401:1

400
401// PrepareRetry is called before retry operation. It can be used for example to re-sign the request
402type PrepareRetry func(req *http.Request) error
406:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:406:6

405// like automatic retries to tolerate minor outages.
406type Client struct {
407 HTTPClient *http.Client // Internal HTTP client.
408:13use-anyuse any instead of interface{}

client.go:408:13

407 HTTPClient *http.Client // Internal HTTP client.
408 Logger interface{} // Customer logger instance. Can be either Logger or LeveledLogger
409
452:27use-anyuse any instead of interface{}

client.go:452:27

451
452func (c *Client) logger() interface{} {
453 c.loggerInit.Do(func() {
472:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:472:6

471// will retry on connection errors and server errors.
472func DefaultRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) {
473 // do not retry on context.Canceled or context.DeadlineExceeded
479:20discarded-error-resulterror result returned by baseRetryPolicy is discarded

client.go:479:20

478 // don't propagate other errors
479 shouldRetry, _ := baseRetryPolicy(resp, err)
480 return shouldRetry, nil
486:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:486:6

485// why it decided to retry or not.
486func ErrorPropagatedRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) {
487 // do not retry on context.Canceled or context.DeadlineExceeded
495:6cognitive-complexityfunction has cognitive complexity 20; maximum is 7

client.go:495:6

494
495func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
496 if err != nil {
495:6cyclomatic-complexityfunction complexity is 12; maximum is 10

client.go:495:6

494
495func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
496 if err != nil {
523:3nil-error-returnthis branch proves an error is non-nil but returns nil in an error result

client.go:523:3

522 // The error is likely recoverable so retry.
523 return true, nil
524 }
551:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:551:6

550// seconds the server states it may be ready to process more requests from this client.
551func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
552 if resp != nil {
551:21redefines-builtin-ididentifier min shadows a predeclared identifier

client.go:551:21

550// seconds the server states it may be ready to process more requests from this client.
551func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
552 if resp != nil {
551:21time-namingtime.Duration name should not include a unit suffix

client.go:551:21

550// seconds the server states it may be ready to process more requests from this client.
551func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
552 if resp != nil {
551:26redefines-builtin-ididentifier max shadows a predeclared identifier

client.go:551:26

550// seconds the server states it may be ready to process more requests from this client.
551func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
552 if resp != nil {
562:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:562:5

561 sleep := time.Duration(mult)
562 if float64(sleep) != mult || sleep > max {
563 sleep = max
579:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:579:5

578func parseRetryAfterHeader(headers []string) (time.Duration, bool) {
579 if len(headers) == 0 || headers[0] == "" {
580 return 0, false
603:1doc-comment-perioddocumentation comment should end with punctuation

client.go:603:1

602
603// LinearJitterBackoff provides a callback for Client.Backoff which will
604// perform linear backoff based on the attempt number and with jitter to
619:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:619:6

618// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...)
619func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
620 // attemptNum always starts at zero but we want to start at 1 for multiplication
619:26redefines-builtin-ididentifier min shadows a predeclared identifier

client.go:619:26

618// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...)
619func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
620 // attemptNum always starts at zero but we want to start at 1 for multiplication
619:26time-namingtime.Duration name should not include a unit suffix

client.go:619:26

618// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...)
619func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
620 // attemptNum always starts at zero but we want to start at 1 for multiplication
619:31redefines-builtin-ididentifier max shadows a predeclared identifier

client.go:619:31

618// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...)
619func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
620 // attemptNum always starts at zero but we want to start at 1 for multiplication
619:66unused-parameterparameter resp is unused

client.go:619:66

618// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...)
619func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
620 // attemptNum always starts at zero but we want to start at 1 for multiplication
621:2modifies-parameterassignment modifies parameter attemptNum

client.go:621:2

620 // attemptNum always starts at zero but we want to start at 1 for multiplication
621 attemptNum++
622
647:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:647:6

646// LinearJitterBackoff.
647func RateLimitLinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
648 if resp != nil {
647:35redefines-builtin-ididentifier min shadows a predeclared identifier

client.go:647:35

646// LinearJitterBackoff.
647func RateLimitLinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
648 if resp != nil {
647:35time-namingtime.Duration name should not include a unit suffix

client.go:647:35

646// LinearJitterBackoff.
647func RateLimitLinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
648 if resp != nil {
647:40redefines-builtin-ididentifier max shadows a predeclared identifier

client.go:647:40

646// LinearJitterBackoff.
647func RateLimitLinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
648 if resp != nil {
661:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:661:6

660// closed.
661func PassthroughErrorHandler(resp *http.Response, err error, _ int) (*http.Response, error) {
662 return resp, err
666:18cognitive-complexityfunction has cognitive complexity 68; maximum is 7

client.go:666:18

665// Do wraps calling an HTTP method with retries.
666func (c *Client) Do(req *Request) (*http.Response, error) {
667 c.clientInit.Do(func() {
666:18cyclomatic-complexityfunction complexity is 49; maximum is 10

client.go:666:18

665// Do wraps calling an HTTP method with retries.
666func (c *Client) Do(req *Request) (*http.Response, error) {
667 c.clientInit.Do(func() {
666:18function-lengthfunction has 87 statements and 178 lines; maximum is 50 statements or 75 lines

client.go:666:18

665// Do wraps calling an HTTP method with retries.
666func (c *Client) Do(req *Request) (*http.Response, error) {
667 c.clientInit.Do(func() {
701:5modifies-parameterassignment modifies parameter req

client.go:701:5

700 if c, ok := body.(io.ReadCloser); ok {
701 req.Body = c
702 } else {
703:5modifies-parameterassignment modifies parameter req

client.go:703:5

702 } else {
703 req.Body = io.NopCloser(body)
704 }
719:17unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

client.go:719:17

718 // Attempt the request
719 resp, doErr = c.HTTPClient.Do(req.Request)
720
719:32external-call-in-loopnet/http.Do is called synchronously inside a loop; batch or move the external operation outside the loop

client.go:719:32

718 // Attempt the request
719 resp, doErr = c.HTTPClient.Do(req.Request)
720
723:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:723:6

722 shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, doErr)
723 if !shouldRetry && doErr == nil && req.responseHandler != nil {
724 respErr = req.responseHandler(resp)
768:21possible-nil-dereferencepointer is dereferenced on a path where its nil check does not prove it is non-nil

client.go:768:21

767 if doErr == nil {
768 c.drainBody(resp.Body)
769 }
796:3modifies-parameterassignment modifies parameter req

client.go:796:3

795 httpreq := *req.Request
796 req.Request = &httpreq
797
807:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:807:5

806 // this is the closest we have to success criteria
807 if doErr == nil && respErr == nil && checkErr == nil && prepareErr == nil && !shouldRetry {
808 return resp, nil
807:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:807:5

806 // this is the closest we have to success criteria
807 if doErr == nil && respErr == nil && checkErr == nil && prepareErr == nil && !shouldRetry {
808 return resp, nil
807:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:807:5

806 // this is the closest we have to success criteria
807 if doErr == nil && respErr == nil && checkErr == nil && prepareErr == nil && !shouldRetry {
808 return resp, nil
862:10import-shadowingidentifier url shadows an imported package

client.go:862:10

861// Get is a shortcut for doing a GET request without making a new client.
862func Get(url string) (*http.Response, error) {
863 return defaultClient.Get(url)
867:22import-shadowingidentifier url shadows an imported package

client.go:867:22

866// Get is a convenience helper for doing simple GET requests.
867func (c *Client) Get(url string) (*http.Response, error) {
868 req, err := NewRequest("GET", url, nil)
876:11import-shadowingidentifier url shadows an imported package

client.go:876:11

875// Head is a shortcut for doing a HEAD request without making a new client.
876func Head(url string) (*http.Response, error) {
877 return defaultClient.Head(url)
881:23import-shadowingidentifier url shadows an imported package

client.go:881:23

880// Head is a convenience method for doing simple HEAD requests.
881func (c *Client) Head(url string) (*http.Response, error) {
882 req, err := NewRequest("HEAD", url, nil)
891:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:891:6

890// The bodyType parameter sets the "Content-Type" header of the request.
891func Post(url, bodyType string, body interface{}) (*http.Response, error) {
892 return defaultClient.Post(url, bodyType, body)
891:11import-shadowingidentifier url shadows an imported package

client.go:891:11

890// The bodyType parameter sets the "Content-Type" header of the request.
891func Post(url, bodyType string, body interface{}) (*http.Response, error) {
892 return defaultClient.Post(url, bodyType, body)
891:38use-anyuse any instead of interface{}

client.go:891:38

890// The bodyType parameter sets the "Content-Type" header of the request.
891func Post(url, bodyType string, body interface{}) (*http.Response, error) {
892 return defaultClient.Post(url, bodyType, body)
897:18exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:897:18

896// The bodyType parameter sets the "Content-Type" header of the request.
897func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error) {
898 req, err := NewRequest("POST", url, body)
897:23import-shadowingidentifier url shadows an imported package

client.go:897:23

896// The bodyType parameter sets the "Content-Type" header of the request.
897func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error) {
898 req, err := NewRequest("POST", url, body)
897:50use-anyuse any instead of interface{}

client.go:897:50

896// The bodyType parameter sets the "Content-Type" header of the request.
897func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error) {
898 req, err := NewRequest("POST", url, body)
908:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:908:6

907// a new client.
908func PostForm(url string, data url.Values) (*http.Response, error) {
909 return defaultClient.PostForm(url, data)
908:15import-shadowingidentifier url shadows an imported package

client.go:908:15

907// a new client.
908func PostForm(url string, data url.Values) (*http.Response, error) {
909 return defaultClient.PostForm(url, data)
914:18exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:914:18

913// pre-filled url.Values form data.
914func (c *Client) PostForm(url string, data url.Values) (*http.Response, error) {
915 return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
914:27import-shadowingidentifier url shadows an imported package

client.go:914:27

913// pre-filled url.Values form data.
914func (c *Client) PostForm(url string, data url.Values) (*http.Response, error) {
915 return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
920:18exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:920:18

919// shims in a *retryablehttp.Client for added retries.
920func (c *Client) StandardClient() *http.Client {
921 return &http.Client{

client_test.go120

1:1file-length-limitfile has 1406 lines; maximum is 500

client_test.go:1:1

1// Copyright IBM Corp. 2015, 2025
2// SPDX-License-Identifier: MPL-2.0
1:1formatfile is not formatted

client_test.go:1:1

1// Copyright IBM Corp. 2015, 2025
2// SPDX-License-Identifier: MPL-2.0
  • Fix (safe): run `strider fmt client_test.go`
26:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:26:6

25
26func TestRequest(t *testing.T) {
27 // Fails on invalid request
34:29insecure-url-schemeURL uses insecure http scheme

client_test.go:34:29

33 // Works with no request body
34 _, err = NewRequest("GET", "http://foo", nil)
35 if err != nil {
41:25add-constantstring literal "GET" appears more than twice; define a constant

client_test.go:41:25

40 body := bytes.NewReader([]byte("yo"))
41 req, err := NewRequest("GET", "/", body)
42 if err != nil {
48:36optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client_test.go:48:36

47 req.Header.Set("X-Test", "foo")
48 if v, ok := req.Header["X-Test"]; !ok || len(v) != 1 || v[0] != "foo" {
49 t.Fatalf("bad headers: %v", req.Header)
58:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:58:6

57
58func TestFromRequest(t *testing.T) {
59 // Works with no request body
60:34standard-http-method-constantreplace the HTTP method literal with http.MethodGet

client_test.go:60:34

59 // Works with no request body
60 httpReq, err := http.NewRequest("GET", "http://foo", nil)
61 if err != nil {
60:41insecure-url-schemeURL uses insecure http scheme

client_test.go:60:41

59 // Works with no request body
60 httpReq, err := http.NewRequest("GET", "http://foo", nil)
61 if err != nil {
62:12add-constantstring literal "err: %v" appears more than twice; define a constant

client_test.go:62:12

61 if err != nil {
62 t.Fatalf("err: %v", err)
63 }
71:33standard-http-method-constantreplace the HTTP method literal with http.MethodGet

client_test.go:71:33

70 body := bytes.NewReader([]byte("yo"))
71 httpReq, err = http.NewRequest("GET", "/", body)
72 if err != nil {
81:21add-constantstring literal "X-Test" appears more than twice; define a constant

client_test.go:81:21

80 // Preserves headers
81 httpReq.Header.Set("X-Test", "foo")
82 if v, ok := req.Header["X-Test"]; !ok || len(v) != 1 || v[0] != "foo" {
81:31add-constantstring literal "foo" appears more than twice; define a constant

client_test.go:81:31

80 // Preserves headers
81 httpReq.Header.Set("X-Test", "foo")
82 if v, ok := req.Header["X-Test"]; !ok || len(v) != 1 || v[0] != "foo" {
82:36optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client_test.go:82:36

81 httpReq.Header.Set("X-Test", "foo")
82 if v, ok := req.Header["X-Test"]; !ok || len(v) != 1 || v[0] != "foo" {
83 t.Fatalf("bad headers: %v", req.Header)
94:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

client_test.go:94:1

93// custom type here
94type custReader struct {
95 val string
108:3modifies-parameterassignment modifies parameter p

client_test.go:108:3

107 for i = 0; i < len(p) && i+c.pos < len(c.val); i++ {
108 p[i] = c.val[i+c.pos]
109 }
114:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:114:6

113
114func TestClient_Do(t *testing.T) {
115 testBytes := []byte("hello")
136:6cognitive-complexityfunction has cognitive complexity 17; maximum is 7

client_test.go:136:6

135
136func testClientDo(t *testing.T, body interface{}) {
137 // Create a request
136:6cyclomatic-complexityfunction complexity is 21; maximum is 10

client_test.go:136:6

135
136func testClientDo(t *testing.T, body interface{}) {
137 // Create a request
136:6function-lengthfunction has 67 statements and 130 lines; maximum is 50 statements or 75 lines

client_test.go:136:6

135
136func testClientDo(t *testing.T, body interface{}) {
137 // Create a request
136:38use-anyuse any instead of interface{}

client_test.go:136:38

135
136func testClientDo(t *testing.T, body interface{}) {
137 // Create a request
138:32insecure-url-schemeURL uses insecure http scheme

client_test.go:138:32

137 // Create a request
138 req, err := NewRequest("PUT", "http://127.0.0.1:28934/v1/foo", body)
139 if err != nil {
172:22nested-structsmove nested anonymous struct types to named declarations

client_test.go:172:22

171 var resp *http.Response
172 doneCh := make(chan struct{})
173 errCh := make(chan error, 1)
192:10redundant-conversionconversion from int64 to the identical type is redundant

client_test.go:192:10

191 // errors.
192 code := int64(500)
193 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
212:22add-constantstring literal "hello" appears more than twice; define a constant

client_test.go:212:22

211 }
212 expected := []byte("hello")
213 if !bytes.Equal(body, expected) {
226:2import-shadowingidentifier errors shadows an imported package

client_test.go:226:2

225 defer list.Close()
226 errors := make(chan error, 1)
227 go func() {
267:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

client_test.go:267:6

266
267func TestClient_Do_WithResponseHandler(t *testing.T) {
268 // Create the client. Use short retry windows so we fail faster.
267:6cyclomatic-complexityfunction complexity is 11; maximum is 10

client_test.go:267:6

266
267func TestClient_Do_WithResponseHandler(t *testing.T) {
268 // Create the client. Use short retry windows so we fail faster.
267:6function-lengthfunction has 37 statements and 94 lines; maximum is 50 statements or 75 lines

client_test.go:267:6

266
267func TestClient_Do_WithResponseHandler(t *testing.T) {
268 // Create the client. Use short retry windows so we fail faster.
267:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:267:6

266
267func TestClient_Do_WithResponseHandler(t *testing.T) {
268 // Create the client. Use short retry windows so we fail faster.
290:13nested-structsmove nested anonymous struct types to named declarations

client_test.go:290:13

289 var shouldSucceed bool
290 tests := []struct {
291 name string
336:18test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:336:18

335 for _, tt := range tests {
336 t.Run(tt.name, func(t *testing.T) {
337 checks = 0
362:6cognitive-complexityfunction has cognitive complexity 17; maximum is 7

client_test.go:362:6

361
362func TestClient_Do_WithPrepareRetry(t *testing.T) {
363 // Create the client. Use short retry windows so we fail faster.
362:6cyclomatic-complexityfunction complexity is 16; maximum is 10

client_test.go:362:6

361
362func TestClient_Do_WithPrepareRetry(t *testing.T) {
363 // Create the client. Use short retry windows so we fail faster.
362:6function-lengthfunction has 51 statements and 121 lines; maximum is 50 statements or 75 lines

client_test.go:362:6

361
362func TestClient_Do_WithPrepareRetry(t *testing.T) {
363 // Create the client. Use short retry windows so we fail faster.
362:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:362:6

361
362func TestClient_Do_WithPrepareRetry(t *testing.T) {
363 // Create the client. Use short retry windows so we fail faster.
392:13nested-structsmove nested anonymous struct types to named declarations

client_test.go:392:13

391 var shouldSucceed bool
392 tests := []struct {
393 name string
416:23add-constantstring literal "retryable failure" appears more than twice; define a constant

client_test.go:416:23

415 handler: func(*http.Response) error {
416 return errors.New("retryable failure")
417 },
444:18test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:444:18

443 for _, tt := range tests {
444 t.Run(tt.name, func(t *testing.T) {
445 checks = 0
484:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:484:6

483
484func TestClient_Do_fails(t *testing.T) {
485 // Mock server which always responds 500.
497:13nested-structsmove nested anonymous struct types to named declarations

client_test.go:497:13

496
497 tests := []struct {
498 url string
498:3import-shadowingidentifier url shadows an imported package

client_test.go:498:3

497 tests := []struct {
498 url string
499 name string
524:18test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:524:18

523 for _, tt := range tests {
524 t.Run(tt.name, func(t *testing.T) {
525 // Create the client. Use short retry windows so we fail faster.
547:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:547:6

546
547func TestClient_Get(t *testing.T) {
548 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
564:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:564:2

563 }
564 resp.Body.Close()
565}
567:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:567:6

566
567func TestClient_RequestLogHook(t *testing.T) {
568 t.Run("RequestLogHook successfully called with default Logger", func(t *testing.T) {
568:66test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:568:66

567func TestClient_RequestLogHook(t *testing.T) {
568 t.Run("RequestLogHook successfully called with default Logger", func(t *testing.T) {
569 testClientRequestLogHook(t, defaultLogger)
571:62test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:571:62

570 })
571 t.Run("RequestLogHook successfully called with nil Logger", func(t *testing.T) {
572 testClientRequestLogHook(t, nil)
574:68test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:574:68

573 })
574 t.Run("RequestLogHook successfully called with nil typed Logger", func(t *testing.T) {
575 testClientRequestLogHook(t, Logger(nil))
577:75test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:577:75

576 })
577 t.Run("RequestLogHook successfully called with nil typed LeveledLogger", func(t *testing.T) {
578 testClientRequestLogHook(t, LeveledLogger(nil))
582:52use-anyuse any instead of interface{}

client_test.go:582:52

581
582func testClientRequestLogHook(t *testing.T, logger interface{}) {
583 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
585:13add-constantstring literal "bad method: %s" appears more than twice; define a constant

client_test.go:585:13

584 if r.Method != "GET" {
585 t.Fatalf("bad method: %s", r.Method)
586 }
587:22add-constantstring literal "/foo/bar" appears more than twice; define a constant

client_test.go:587:22

586 }
587 if r.RequestURI != "/foo/bar" {
588 t.Fatalf("bad uri: %s", r.RequestURI)
588:13add-constantstring literal "bad uri: %s" appears more than twice; define a constant

client_test.go:588:13

587 if r.RequestURI != "/foo/bar" {
588 t.Fatalf("bad uri: %s", r.RequestURI)
589 }
622:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:622:2

621 }
622 resp.Body.Close()
623
629:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:629:6

628
629func TestClient_ResponseLogHook(t *testing.T) {
630 t.Run("ResponseLogHook successfully called with hclog Logger", func(t *testing.T) {
630:65test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:630:65

629func TestClient_ResponseLogHook(t *testing.T) {
630 t.Run("ResponseLogHook successfully called with hclog Logger", func(t *testing.T) {
631 buf := new(bytes.Buffer)
637:63test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:637:63

636 })
637 t.Run("ResponseLogHook successfully called with nil Logger", func(t *testing.T) {
638 buf := new(bytes.Buffer)
641:69test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:641:69

640 })
641 t.Run("ResponseLogHook successfully called with nil typed Logger", func(t *testing.T) {
642 buf := new(bytes.Buffer)
645:76test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:645:76

644 })
645 t.Run("ResponseLogHook successfully called with nil typed LeveledLogger", func(t *testing.T) {
646 buf := new(bytes.Buffer)
651:6cognitive-complexityfunction has cognitive complexity 17; maximum is 7

client_test.go:651:6

650
651func testClientResponseLogHook(t *testing.T, l interface{}, buf *bytes.Buffer) {
652 passAfter := time.Now().Add(100 * time.Millisecond)
651:6cyclomatic-complexityfunction complexity is 13; maximum is 10

client_test.go:651:6

650
651func testClientResponseLogHook(t *testing.T, l interface{}, buf *bytes.Buffer) {
652 passAfter := time.Now().Add(100 * time.Millisecond)
651:48use-anyuse any instead of interface{}

client_test.go:651:48

650
651func testClientResponseLogHook(t *testing.T, l interface{}, buf *bytes.Buffer) {
652 passAfter := time.Now().Add(100 * time.Millisecond)
711:33add-constantstring literal "test_200_body" appears more than twice; define a constant

client_test.go:711:33

710 if string(body) != "test_200_body" {
711 t.Fatalf("expect %q, got %q", "test_200_body", string(body))
712 }
724:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:724:6

723
724func TestClient_NewRequestWithContext(t *testing.T) {
725 ctx, cancel := context.WithCancel(context.Background())
736:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:736:6

735
736func TestClient_RequestWithContext(t *testing.T) {
737 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
740:13add-constantstring literal "failed to write: %v" appears more than twice; define a constant

client_test.go:740:13

739 if _, err := w.Write([]byte("test_200_body")); err != nil {
740 t.Fatalf("failed to write: %v", err)
741 }
777:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:777:6

776
777func TestClient_CheckRetry(t *testing.T) {
778 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
779:17add-constantstring literal "test_500_body" appears more than twice; define a constant

client_test.go:779:17

778 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
779 http.Error(w, "test_500_body", http.StatusInternalServerError)
780 }))
821:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:821:6

820
821func TestParseRetryAfterHeader(t *testing.T) {
822 testStaticTime(t)
823:13nested-structsmove nested anonymous struct types to named declarations

client_test.go:823:13

822 testStaticTime(t)
823 tests := []struct {
824 name string
840:20test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:840:20

839 for _, test := range tests {
840 t.Run(test.name, func(t *testing.T) {
841 sleep, ok := parseRetryAfterHeader(test.headers)
852:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:852:6

851
852func TestClient_DefaultBackoff(t *testing.T) {
853 testStaticTime(t)
854:13nested-structsmove nested anonymous struct types to named declarations

client_test.go:854:13

853 testStaticTime(t)
854 tests := []struct {
855 name string
859:52add-constantstring literal "2" appears more than twice; define a constant

client_test.go:859:52

858 }{
859 {"http_429_seconds", http.StatusTooManyRequests, "2"},
860 {"http_429_date", http.StatusTooManyRequests, "Fri, 31 Dec 1999 23:59:59 GMT"},
862:52add-constantstring literal "Fri, 31 Dec 1999 23:59:59 GMT" appears more than twice; define a constant

client_test.go:862:52

861 {"http_503_seconds", http.StatusServiceUnavailable, "2"},
862 {"http_503_date", http.StatusServiceUnavailable, "Fri, 31 Dec 1999 23:59:59 GMT"},
863 }
865:20test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:865:20

864 for _, test := range tests {
865 t.Run(test.name, func(t *testing.T) {
866 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
878:20discarded-error-resulterror result returned by DefaultRetryPolicy is discarded

client_test.go:878:20

877 client.CheckRetry = func(_ context.Context, resp *http.Response, err error) (bool, error) {
878 retryable, _ = DefaultRetryPolicy(context.Background(), resp, err)
879 retryAfter = DefaultBackoff(client.RetryWaitMin, client.RetryWaitMax, 1, resp)
899:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:899:6

898
899func TestClient_DefaultRetryPolicy_TLS(t *testing.T) {
900 ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
921:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:921:6

920
921func TestClient_DefaultRetryPolicy_redirects(t *testing.T) {
922 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
923:23add-constantstring literal "/" appears more than twice; define a constant

client_test.go:923:23

922 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
923 http.Redirect(w, r, "/", http.StatusFound)
924 }))
943:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:943:6

942
943func TestClient_DefaultRetryPolicy_invalidscheme(t *testing.T) {
944 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
956:2import-shadowingidentifier url shadows an imported package

client_test.go:956:2

955
956 url := strings.Replace(ts.URL, "http", "ftp", 1)
957 _, err := client.Get(url)
962:12add-constantstring literal "expected 1 attempt, got %d" appears more than twice; define a constant

client_test.go:962:12

961 if attempts != 1 {
962 t.Fatalf("expected 1 attempt, got %d", attempts)
963 }
966:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:966:6

965
966func TestClient_DefaultRetryPolicy_invalidheadername(t *testing.T) {
967 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
993:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:993:6

992
993func TestClient_DefaultRetryPolicy_invalidheadervalue(t *testing.T) {
994 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1020:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1020:6

1019
1020func TestClient_CheckRetryStop(t *testing.T) {
1021 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1038:12add-constantstring literal "CheckRetry called %d times, expected 1" appears more than twice; define a constant

client_test.go:1038:12

1037 if called != 1 {
1038 t.Fatalf("CheckRetry called %d times, expected 1", called)
1039 }
1046:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1046:6

1045
1046func TestClient_Head(t *testing.T) {
1047 // Mock server which always responds 200.
1064:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:1064:2

1063 }
1064 resp.Body.Close()
1065}
1067:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1067:6

1066
1067func TestClient_Post(t *testing.T) {
1068 // Mock server which always responds 200.
1102:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:1102:2

1101 }
1102 resp.Body.Close()
1103}
1105:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1105:6

1104
1105func TestClient_PostForm(t *testing.T) {
1106 // Mock server which always responds 200.
1108:18add-constantstring literal "POST" appears more than twice; define a constant

client_test.go:1108:18

1107 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1108 if r.Method != "POST" {
1109 t.Fatalf("bad method: %s", r.Method)
1121:13add-constantstring literal "err: %s" appears more than twice; define a constant

client_test.go:1121:13

1120 if err != nil {
1121 t.Fatalf("err: %s", err)
1122 }
1125:13add-constantstring literal "bad: %v" appears more than twice; define a constant

client_test.go:1125:13

1124 if !bytes.Equal(body, expected) {
1125 t.Fatalf("bad: %v", body)
1126 }
1143:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:1143:2

1142 }
1143 resp.Body.Close()
1144}
1146:6function-lengthfunction has 6 statements and 106 lines; maximum is 50 statements or 75 lines

client_test.go:1146:6

1145
1146func TestBackoff_RateLimitLinearJitterBackoff(t *testing.T) {
1147 testCases := []struct {
1146:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1146:6

1145
1146func TestBackoff_RateLimitLinearJitterBackoff(t *testing.T) {
1147 testCases := []struct {
1147:17nested-structsmove nested anonymous struct types to named declarations

client_test.go:1147:17

1146func TestBackoff_RateLimitLinearJitterBackoff(t *testing.T) {
1147 testCases := []struct {
1148 name string
1149:3redefines-builtin-ididentifier min shadows a predeclared identifier

client_test.go:1149:3

1148 name string
1149 min time.Duration
1150 max time.Duration
1150:3redefines-builtin-ididentifier max shadows a predeclared identifier

client_test.go:1150:3

1149 min time.Duration
1150 max time.Duration
1151 headers http.Header
1186:5add-constantstring literal "Retry-After" appears more than twice; define a constant

client_test.go:1186:5

1185 headers: http.Header{
1186 "Retry-After": []string{"2"},
1187 },
1241:18test-parallelismconsider calling t.Parallel() when this subtest begins

client_test.go:1241:18

1240 for _, tc := range testCases {
1241 t.Run(tc.name, func(t *testing.T) {
1242 got := RateLimitLinearJitterBackoff(tc.min, tc.max, 0, &http.Response{
1242:59range-value-addresstaking the address of range value tc can be misleading

client_test.go:1242:59

1241 t.Run(tc.name, func(t *testing.T) {
1242 got := RateLimitLinearJitterBackoff(tc.min, tc.max, 0, &http.Response{
1243 StatusCode: tc.responseCode,
1253:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1253:6

1252
1253func TestBackoff(t *testing.T) {
1254 type tcase struct {
1255:3redefines-builtin-ididentifier min shadows a predeclared identifier

client_test.go:1255:3

1254 type tcase struct {
1255 min time.Duration
1256 max time.Duration
1256:3redefines-builtin-ididentifier max shadows a predeclared identifier

client_test.go:1256:3

1255 min time.Duration
1256 max time.Duration
1257 i int
1306:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1306:6

1305
1306func TestClient_BackoffCustom(t *testing.T) {
1307 var retries int32
1310:24redefines-builtin-ididentifier min shadows a predeclared identifier

client_test.go:1310:24

1309 client := NewClient()
1310 client.Backoff = func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
1311 atomic.AddInt32(&retries, 1)
1310:29redefines-builtin-ididentifier max shadows a predeclared identifier

client_test.go:1310:29

1309 client := NewClient()
1310 client.Backoff = func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
1311 atomic.AddInt32(&retries, 1)
1329:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:1329:2

1328 }
1329 resp.Body.Close()
1330 if retries != int32(client.RetryMax) {
1335:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1335:6

1334
1335func TestClient_StandardClient(t *testing.T) {
1336 // Create a retryable HTTP client.
1343:28unchecked-type-assertionuse the checked two-result form of the type assertion

client_test.go:1343:28

1342 // Ensure the underlying retrying client is set properly.
1343 if v := standard.Transport.(*RoundTripper).Client; v != client {
1344 t.Fatalf("expected %v, got %v", client, v)
1348:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

client_test.go:1348:6

1347
1348func TestClient_RedirectWithBody(t *testing.T) {
1349 var redirects int32
1348:6cyclomatic-complexityfunction complexity is 11; maximum is 10

client_test.go:1348:6

1347
1348func TestClient_RedirectWithBody(t *testing.T) {
1349 var redirects int32
1348:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:1348:6

1347
1348func TestClient_RedirectWithBody(t *testing.T) {
1349 var redirects int32
1352:3single-case-switchswitch with one case can be replaced by an if statement

client_test.go:1352:3

1351 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1352 switch r.RequestURI {
1353 case "/redirect":
1381:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:1381:2

1380 }
1381 resp.Body.Close()
1382
1396:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_test.go:1396:2

1395 }
1396 resp.Body.Close()
1397

roundtripper.go2

4:9package-commentspackage should have a documentation comment

roundtripper.go:4:9

3
4package retryablehttp
5
19:6exported-declaration-commentexported type should have a comment beginning with its name

roundtripper.go:19:6

18// configuration.
19type RoundTripper struct {
20 // The client to use during requests. If nil, the default retryablehttp

roundtripper_test.go15

1:1formatfile is not formatted

roundtripper_test.go:1:1

1// Copyright IBM Corp. 2015, 2025
2// SPDX-License-Identifier: MPL-2.0
  • Fix (safe): run `strider fmt roundtripper_test.go`
19:6test-parallelismconsider calling t.Parallel() when this test begins

roundtripper_test.go:19:6

18
19func TestRoundTripper_implements(t *testing.T) {
20 // Compile-time proof of interface satisfaction.
19:34unused-parameterparameter t is unused

roundtripper_test.go:19:34

18
19func TestRoundTripper_implements(t *testing.T) {
20 // Compile-time proof of interface satisfaction.
24:6test-parallelismconsider calling t.Parallel() when this test begins

roundtripper_test.go:24:6

23
24func TestRoundTripper_init(t *testing.T) {
25 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
34:12discarded-error-resulterror result returned by http.NewRequest is discarded

roundtripper_test.go:34:12

33 // RoundTrip once.
34 req, _ := http.NewRequest("GET", ts.URL, nil)
35 if _, err := rt.RoundTrip(req); err != nil {
34:28standard-http-method-constantreplace the HTTP method literal with http.MethodGet

roundtripper_test.go:34:28

33 // RoundTrip once.
34 req, _ := http.NewRequest("GET", ts.URL, nil)
35 if _, err := rt.RoundTrip(req); err != nil {
48:11discarded-error-resulterror result returned by http.NewRequest is discarded

roundtripper_test.go:48:11

47 // RoundTrip again.
48 req, _ = http.NewRequest("GET", ts.URL, nil)
49 if _, err := rt.RoundTrip(req); err != nil {
48:27standard-http-method-constantreplace the HTTP method literal with http.MethodGet

roundtripper_test.go:48:27

47 // RoundTrip again.
48 req, _ = http.NewRequest("GET", ts.URL, nil)
49 if _, err := rt.RoundTrip(req); err != nil {
59:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

roundtripper_test.go:59:6

58
59func TestRoundTripper_RoundTrip(t *testing.T) {
60 var reqCount int32 = 0
59:6test-parallelismconsider calling t.Parallel() when this test begins

roundtripper_test.go:59:6

58
59func TestRoundTripper_RoundTrip(t *testing.T) {
60 var reqCount int32 = 0
60:23var-declarationomit the explicit zero value from the variable declaration

roundtripper_test.go:60:23

59func TestRoundTripper_RoundTrip(t *testing.T) {
60 var reqCount int32 = 0
61
96:35add-constantstring literal "success!" appears more than twice; define a constant

roundtripper_test.go:96:35

95 } else if string(v) != "success!" {
96 t.Fatalf("expected %q, got %q", "success!", v)
97 }
100:6test-parallelismconsider calling t.Parallel() when this test begins

roundtripper_test.go:100:6

99
100func TestRoundTripper_TransportFailureErrorHandling(t *testing.T) {
101 // Make a client with some custom settings to verify they are used.
115:8insecure-url-schemeURL uses insecure http scheme

roundtripper_test.go:115:8

114 Op: "Get",
115 URL: "http://999.999.999.999:999/",
116 Err: &net.OpError{
129:23insecure-url-schemeURL uses insecure http scheme

roundtripper_test.go:129:23

128 client := retryClient.StandardClient()
129 _, err := client.Get("http://999.999.999.999:999/")
130