go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resty retry function does not work in Slack as custom http client

rts-gordon opened this issue · comments

My program send message to Slack channel via slack-go, I used a Resty as a custom http client and set it retry 3 times, but the retry function does not work with slack-go.

I changed to another http client retryablehttp, the retry function works well with slack-go.

slack-go code:

// transfor resty.Client to http.Client
httpClient = InitHttpClient().GetClient()
slack.PostWebhookCustomHTTP(url, httpClient, &msg)

Resty httpClient:

func InitHttpClient() *resty.Client {
	return resty.New().
		SetRetryCount(3).
		SetRetryWaitTime(1 * time.Second).
		SetRetryMaxWaitTime(20 * time.Second)
}

I studied retryablehttp code found that StandardClient returns a stdlib *http.Client with a custom Transport, which shims in a *retryablehttp.Client for added retries. But resty.GetClient just return c.httpClient, can resty.GetClient implement the same retry function? thank you.

Versions
Go: v1.22
slack-go/slack: v0.12.5
Resty: v2.12.0
retryablehttp: v0.7.5

@rts-gordon Thanks for reaching out. If I recall correctly, resty.GetClient is the underlying Go HTTP client instance returned as-is. The returned client does not accommodate all the Resty feature(s) today.

Can you fork the Resty, add the implementation, and test it? If it works as-is, you could submit a PR. Otherwise, I will consider it part of the v3 design.

@jeevatkm
Maybe we can implement this in v3. Thanks.