扩展事件定义

This commit is contained in:
2024-06-01 18:41:26 +08:00
parent 196e81191a
commit 4d38cc11c3
6 changed files with 125 additions and 75 deletions

View File

@ -7,20 +7,6 @@
// Date : 2024-05-31 14:51
package define
// BeforeRequestHandler 请求开始之前的handler
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:51 2024/5/31
type BeforeRequestHandler func(req *Request)
// AfterResponse 请求完成之后的处理handler
//
// Author : zhangdeman001@ke.com<张德满>
//
// Date : 14:53 2024/5/31
type AfterResponse func(req *Request, rep *Response)
// Http4xxHandler 4xx handler
//
// Author : go_developer@163.com<白茶清欢>
@ -35,9 +21,23 @@ type Http4xxHandler func(req *Request, rep *Response)
// Date : 14:55 2024/5/31
type Http5xxHandler func(req *Request, rep *Response)
// PanicHandler panic的处理
// HttpBusinessErrorHandler 接口请求业务错误
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:56 2024/5/31
type PanicHandler func(req *Request, rep *Response)
// Date : 18:04 2024/6/1
type HttpBusinessErrorHandler func(req *Request, rep *Response)
// RequestSendErrorHandler 请求发送失败的处理逻辑
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:23 2024/6/1
type RequestSendErrorHandler func(req *Request)
// RequestFinishHandler 请求最终完成事件, 不区分成功 OR 失败
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:34 2024/6/1
type RequestFinishHandler func(req *Request, rep *Response)

View File

@ -7,7 +7,9 @@
// Date : 2024-05-31 12:34
package define
import "github.com/go-resty/resty/v2"
import (
"github.com/go-resty/resty/v2"
)
// Response 响应的数据结构定义
//
@ -30,6 +32,23 @@ type Response struct {
UsedTime int64 `json:"used_time"` // 请求耗时 : ms
RestyResponse *resty.Response `json:"-"` // 请求返回
IsSuccess bool `json:"is_success"` // 是否请求成功
RequestCount int64 `json:"request_count"` // 请求次数
FailInfoList []any `json:"fail_info_list"` // 请求失败信息记录
RequestCount int `json:"request_count"` // 请求次数
FailInfo *ResponseFileInfo `json:"fail_info"` // 请求失败信息记录
}
// ResponseFileInfo 失败信息
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:48 2024/6/1
type ResponseFileInfo struct {
Type string `json:"type"` // 失败类型
Message string `json:"message"` // 失败信息
}
const (
RequestFailTypeSend = "SEND_REQUEST_FAIL" // 发送请求即失败, 问题出现在客户端
RequestFailTypeClientError = "CLIENT_REQUEST_ERROR" // 请求失败, 原因出在客户端, 对应http code 4xx
RequestFailTypeServerError = "SERVER_DEAL_ERROR" // 服务端处理失败, 对应 http code 5xx
RequestFailTypeBusinessError = "SERVICE_BUSINESS_ERROR" // 返回状态码为200, 但是业务状态码非成功
)