增加重试配置初始化 + 重试逻辑处理

This commit is contained in:
2024-05-31 18:51:31 +08:00
parent 0ba0f7dced
commit 196e81191a
4 changed files with 44 additions and 3 deletions

View File

@ -88,9 +88,36 @@ func (hc *HttpClient) GetRestyClient() *resty.Client {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:52 2024/5/31
func (hc *HttpClient) Request(reqConfig *define.Request) *define.Response {
func (hc *HttpClient) Request() *define.Response {
hc.Client.OnBeforeRequest(hc.getRequestValidateMiddleware()) // 请求参数验证中间件必注册
hc.Client.OnAfterResponse(hc.getResponseValidateMiddleware()) // 响应验证中间件必注册
hc.request.Send()
var (
err error
)
response := &define.Response{
Header: map[string]string{},
Cookie: map[string]string{},
Body: map[string]any{},
Code: "",
Message: "",
Data: "",
HttpCode: 0,
HttpCodeStatus: "",
ResponseDataRule: nil,
Seq: 0,
RequestStartTime: 0,
FinishRequestTime: 0,
UsedTime: 0,
RestyResponse: nil,
IsSuccess: false,
RequestCount: 0,
FailInfoList: make([]any, 0),
}
for i := 0; i < hc.reqConfig.RetryRule.RetryCount+1; i++ {
if response.RestyResponse, err = hc.request.Send(); nil != err {
}
}
return nil
}