update data handler
This commit is contained in:
parent
83b5e41105
commit
6b5db7cdbd
15
client.go
15
client.go
@ -208,7 +208,7 @@ func (hc *HttpClient) newResponse() *define.Response {
|
|||||||
return &define.Response{
|
return &define.Response{
|
||||||
Header: map[string]string{},
|
Header: map[string]string{},
|
||||||
Cookie: map[string]string{},
|
Cookie: map[string]string{},
|
||||||
Body: "",
|
Body: map[string]any{},
|
||||||
Code: "",
|
Code: "",
|
||||||
Message: "",
|
Message: "",
|
||||||
Data: "",
|
Data: "",
|
||||||
@ -262,13 +262,13 @@ func (hc *HttpClient) fillResponseCookie(response *define.Response) {
|
|||||||
//
|
//
|
||||||
// Date : 21:38 2024/6/5
|
// Date : 21:38 2024/6/5
|
||||||
func (hc *HttpClient) fillResponseBody(response *define.Response) {
|
func (hc *HttpClient) fillResponseBody(response *define.Response) {
|
||||||
response.Body = string(response.RestyResponse.Body())
|
response.Data = string(response.RestyResponse.Body())
|
||||||
response.Code = gjson.Get(response.Body, hc.reqConfig.CodeField).String()
|
response.Code = gjson.Get(response.Data, hc.reqConfig.CodeField).String()
|
||||||
response.Message = gjson.Get(response.Body, hc.reqConfig.MessageField).String()
|
response.Message = gjson.Get(response.Data, hc.reqConfig.MessageField).String()
|
||||||
businessData := gjson.Get(response.Body, hc.reqConfig.DataField)
|
businessData := gjson.Get(response.Data, hc.reqConfig.DataField)
|
||||||
if businessData.Value() == nil {
|
if businessData.Value() == nil {
|
||||||
// data为空指针, 归一化成空对象
|
// data为空指针, 归一化成空对象
|
||||||
response.Data = "{}"
|
response.Body = map[string]any{}
|
||||||
} else {
|
} else {
|
||||||
if businessData.IsArray() {
|
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{}
|
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 ||
|
if key.String() == hc.reqConfig.CodeField ||
|
||||||
key.String() == hc.reqConfig.MessageField ||
|
key.String() == hc.reqConfig.MessageField ||
|
||||||
key.String() == hc.reqConfig.DataField {
|
key.String() == hc.reqConfig.DataField {
|
||||||
|
@ -22,7 +22,7 @@ type Response struct {
|
|||||||
Data string `json:"data"` // 响应body
|
Data string `json:"data"` // 响应body
|
||||||
Code string `json:"code"` // 业务状态码
|
Code string `json:"code"` // 业务状态码
|
||||||
Message string `json:"message"` // 业务状态码描述
|
Message string `json:"message"` // 业务状态码描述
|
||||||
Body string `json:"body"` // 响应数据, 如果 data 本身是 list, 会自动转成 {"list": 真实数据}
|
Body map[string]any `json:"body"` // 响应数据
|
||||||
ExtendData map[string]string `json:"extend_data"` // 除去 code / message / data 之外的其他数据
|
ExtendData map[string]string `json:"extend_data"` // 除去 code / message / data 之外的其他数据
|
||||||
HttpCode int `json:"http_code"` // http状态码
|
HttpCode int `json:"http_code"` // http状态码
|
||||||
HttpCodeStatus string `json:"http_code_status"` // http状态码描述
|
HttpCodeStatus string `json:"http_code_status"` // http状态码描述
|
||||||
|
Loading…
Reference in New Issue
Block a user