From acdb38d475bc676c013b2f4338a2ad4c00266e94 Mon Sep 17 00:00:00 2001 From: Jerry <85411418@qq.com> Date: Thu, 2 Nov 2023 19:12:48 +0800 Subject: [PATCH] update xhttp client --- pkg/xhttp/model.go | 8 ++++---- pkg/xhttp/request.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/xhttp/model.go b/pkg/xhttp/model.go index 4343e0ff..9381a866 100644 --- a/pkg/xhttp/model.go +++ b/pkg/xhttp/model.go @@ -7,8 +7,8 @@ const ( DELETE = "DELETE" PATCH = "PATCH" - ResTypeJSON = "application/json" - ResTypeXML = "application/xml" + ResTypeJSON = "json" + ResTypeXML = "xml" TypeJSON = "json" TypeXML = "xml" @@ -25,7 +25,7 @@ var ( } _ResTypeMap = map[string]string{ - ResTypeJSON: "json", - ResTypeXML: "xml", + ResTypeJSON: "application/json", + ResTypeXML: "application/xml", } ) diff --git a/pkg/xhttp/request.go b/pkg/xhttp/request.go index 1059f670..302ea1a9 100644 --- a/pkg/xhttp/request.go +++ b/pkg/xhttp/request.go @@ -223,13 +223,13 @@ func (r *Request) EndStruct(ctx context.Context, v any) (res *http.Response, err } switch r.responseType { - case string(TypeJSON): + case ResTypeJSON: err = json.Unmarshal(bs, &v) if err != nil { return nil, fmt.Errorf("json.Unmarshal(%s, %+v):%w", string(bs), v, err) } return res, nil - case string(TypeXML): + case ResTypeXML: err = xml.Unmarshal(bs, &v) if err != nil { return nil, fmt.Errorf("xml.Unmarshal(%s, %+v):%w", string(bs), v, err)