1 Star 0 Fork 0

carlmax_my/console-core-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
retry.go 784 Bytes
一键复制 编辑 原始数据 按行查看 历史
carlmax_my 提交于 3个月前 . init project
package httpclient
import (
"context"
"net/http"
"time"
)
const (
// DefaultRetryTimes if request failed, retry 3 times at most
DefaultRetryTimes = 3
// DefaultRetryDelay before retry, wait and delay for 100ms
DefaultRetryDelay = time.Millisecond * 100
)
// RetryVerify Verify parse the body and verify that it is correct
type RetryVerify func(body []byte) (shouldRetry bool)
func shouldRetry(ctx context.Context, httpCode int) bool {
select {
case <-ctx.Done():
return false
default:
}
switch httpCode {
case
_StatusReadRespErr,
_StatusDoReqErr,
http.StatusRequestTimeout,
http.StatusLocked,
http.StatusTooEarly,
http.StatusTooManyRequests,
http.StatusServiceUnavailable,
http.StatusGatewayTimeout:
return true
default:
return false
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/carlmax_my/console-core-go.git
git@gitee.com:carlmax_my/console-core-go.git
carlmax_my
console-core-go
console-core-go
v0.0.11

搜索帮助