update data handler
This commit is contained in:
15
client.go
15
client.go
@ -208,7 +208,7 @@ func (hc *HttpClient) newResponse() *define.Response {
|
||||
return &define.Response{
|
||||
Header: map[string]string{},
|
||||
Cookie: map[string]string{},
|
||||
Body: "",
|
||||
Body: map[string]any{},
|
||||
Code: "",
|
||||
Message: "",
|
||||
Data: "",
|
||||
@ -262,13 +262,13 @@ func (hc *HttpClient) fillResponseCookie(response *define.Response) {
|
||||
//
|
||||
// Date : 21:38 2024/6/5
|
||||
func (hc *HttpClient) fillResponseBody(response *define.Response) {
|
||||
response.Body = string(response.RestyResponse.Body())
|
||||
response.Code = gjson.Get(response.Body, hc.reqConfig.CodeField).String()
|
||||
response.Message = gjson.Get(response.Body, hc.reqConfig.MessageField).String()
|
||||
businessData := gjson.Get(response.Body, hc.reqConfig.DataField)
|
||||
response.Data = string(response.RestyResponse.Body())
|
||||
response.Code = gjson.Get(response.Data, hc.reqConfig.CodeField).String()
|
||||
response.Message = gjson.Get(response.Data, hc.reqConfig.MessageField).String()
|
||||
businessData := gjson.Get(response.Data, hc.reqConfig.DataField)
|
||||
if businessData.Value() == nil {
|
||||
// data为空指针, 归一化成空对象
|
||||
response.Data = "{}"
|
||||
response.Body = map[string]any{}
|
||||
} else {
|
||||
if businessData.IsArray() {
|
||||
// 数组类型的转换
|
||||
@ -284,10 +284,11 @@ func (hc *HttpClient) fillResponseBody(response *define.Response) {
|
||||
})
|
||||
}
|
||||
}
|
||||
_ = serialize.JSON.UnmarshalWithNumber([]byte(response.Data), &response.Body)
|
||||
}
|
||||
|
||||
response.ExtendData = map[string]string{}
|
||||
gjson.Parse(response.Body).ForEach(func(key, value gjson.Result) bool {
|
||||
gjson.Parse(response.Data).ForEach(func(key, value gjson.Result) bool {
|
||||
if key.String() == hc.reqConfig.CodeField ||
|
||||
key.String() == hc.reqConfig.MessageField ||
|
||||
key.String() == hc.reqConfig.DataField {
|
||||
|
Reference in New Issue
Block a user