清理一些无效代码

This commit is contained in:
白茶清欢 2025-05-07 22:19:44 +08:00
parent e02ee1fef9
commit 2cb3d44ec9
2 changed files with 9 additions and 58 deletions

View File

@ -101,14 +101,11 @@ func NewHttpClient(reqConfig *define.Request, reqOption *RequestOption) (*HttpCl
}
restyClient, restyRequest := NewRestyClient(reqConfig)
hc := &HttpClient{
Client: restyClient,
request: restyRequest,
reqOption: reqOption,
reqCfg: reqConfig,
http4xxHandler: make([]define.Http4xxHandler, 0),
http5xxHandler: make([]define.Http5xxHandler, 0),
httpBusinessErrorHandler: make([]define.HttpBusinessErrorHandler, 0),
requestFinishHandler: make([]define.RequestFinishHandler, 0),
Client: restyClient,
request: restyRequest,
reqOption: reqOption,
reqCfg: reqConfig,
requestFinishHandler: make([]define.RequestFinishHandler, 0),
}
hc.OnRequestFinish(func(req *define.Request, rep *define.Response) {
if rep.IsSuccess {
@ -129,41 +126,10 @@ func NewHttpClient(reqConfig *define.Request, reqOption *RequestOption) (*HttpCl
// Date : 15:27 2024/5/31
type HttpClient struct {
*resty.Client
request *resty.Request
reqOption *RequestOption
reqCfg *define.Request
http4xxHandler []define.Http4xxHandler
http5xxHandler []define.Http5xxHandler
httpBusinessErrorHandler []define.HttpBusinessErrorHandler
requestSendErrorHandler []define.RequestSendErrorHandler
requestFinishHandler []define.RequestFinishHandler
}
// OnResponse4xx 4xx处理逻辑
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:20 2024/6/1
func (hc *HttpClient) OnResponse4xx(handlerList ...define.Http4xxHandler) {
hc.http4xxHandler = append(hc.http4xxHandler, handlerList...)
}
// OnResponse5xx 5xx处理逻辑
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:21 2024/6/1
func (hc *HttpClient) OnResponse5xx(handlerList ...define.Http5xxHandler) {
hc.http5xxHandler = append(hc.http5xxHandler, handlerList...)
}
// OnResponseBusinessError 业务错误出路逻辑
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:22 2024/6/1
func (hc *HttpClient) OnResponseBusinessError(handlerList ...define.HttpBusinessErrorHandler) {
hc.httpBusinessErrorHandler = append(hc.httpBusinessErrorHandler, handlerList...)
request *resty.Request
reqOption *RequestOption
reqCfg *define.Request
requestFinishHandler []define.RequestFinishHandler
}
// OnRequestFinish 请求完成事件
@ -175,15 +141,6 @@ func (hc *HttpClient) OnRequestFinish(handlerList ...define.RequestFinishHandler
hc.requestFinishHandler = append(hc.requestFinishHandler, handlerList...)
}
// SetRestyClient 设置client
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:54 2024/5/31
func (hc *HttpClient) SetRestyClient(restyClient *resty.Client) {
hc.Client = restyClient
}
// GetRestyClient 获取 resty client
//
// Author : go_developer@163.com<白茶清欢>

View File

@ -30,16 +30,10 @@ func NewRestyClient(reqConfig *define.Request) (*resty.Client, *resty.Request) {
if nil == reqConfig {
return client, request
}
/*if nil != reqConfig.RateLimiter {
// 设置流控实例
client.SetRateLimiter(reqConfig.RateLimiter)
}*/
formatHeader(reqConfig)
client.SetAllowMethodGetPayload(true) // 配置 GET 请求允许带 Body
client.SetAllowMethodDeletePayload(true) // 配置 DELETE 请求允许带 Body
client.SetJSONEscapeHTML(true) // 处理html实体字符
/*client.SetJSONMarshaler(json.Marshal) // 序列化方法
client.SetJSONUnmarshaler(serialize.JSON.UnmarshalWithNumber) // 反序列化方法*/
request.SetPathParams(reqConfig.PathParam) // 设置path中的参数
query := map[string]string{}