From 62d3c792ce4baf06ba4ec9ebd148ae83e4286fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 14 Feb 2023 15:30:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=93=8D=E5=BA=94=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=20->=20receiver=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpclient.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/httpclient.go b/httpclient.go index 6eaf929..bb8a347 100644 --- a/httpclient.go +++ b/httpclient.go @@ -40,9 +40,10 @@ type httpClient struct { // Date : 14:37 2023/2/14 func (hc *httpClient) Send(requestURL string, method string, header map[string]string, param map[string]interface{}, options httpclient.Map, receiver interface{}) ([]byte, error) { var ( - err error - response *httpclient.Response - c *httpclient.HttpClient + err error + response *httpclient.Response + c *httpclient.HttpClient + responseData []byte ) if nil == param { param = make(map[string]interface{}) @@ -64,7 +65,17 @@ func (hc *httpClient) Send(requestURL string, method string, header map[string]s return nil, fmt.Errorf("%v : %v", response.StatusCode, response.Status) } - return hc.getResponseBody(response) + if responseData, err = hc.getResponseBody(response); nil != err { + return nil, err + } + + if nil == receiver { + return responseData, nil + } + if err = json.Unmarshal(responseData, receiver); nil != err { + return responseData, err + } + return responseData, err } // getResponseBody ...