largeQ
您可以实现自己的重试策略,并将其传递到“客户端”字段。文档参考:https://pkg.go.dev/github.com/hashicorp/go-retryablehttp?utm_source=godoc#Clienthttps://pkg.go.dev/github.com/hashicorp/go-retryablehttp?utm_source=godoc#DefaultRetryPolicy代码参考:https://github.com/hashicorp/go-retryablehttp/blob/02c1586c8f14be23e7eeb522f1094afbabf45e93/client.go#L401https://github.com/hashicorp/go-retryablehttp/blob/02c1586c8f14be23e7eeb522f1094afbabf45e93/client.go#L424代码可能类似于package mainimport ( "context" "net/http" "github.com/hashicorp/go-retryablehttp")func main() { retryClient := retryablehttp.NewClient() retryClient.RetryMax = 10 retryClient.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) { ok, e := retryablehttp.DefaultRetryPolicy(ctx, resp, err) if !ok && resp.StatusCode == http.StatusRequestTimeout { return true, nil // return true for a retry, // if e is nil, // you might want to populate that error // to propagate it. // see https://github.com/hashicorp/go-retryablehttp/blob/02c1586c8f14be23e7eeb522f1094afbabf45e93/client.go#L673 } return ok, e }}