From f5594c56cf17ee7251d37fb23f71c6197f86327e Mon Sep 17 00:00:00 2001 From: roc Date: Tue, 24 Jan 2023 21:03:04 +0800 Subject: [PATCH] Remove SetUnknownResultHandlerFunc --- client.go | 48 +++++++++++++++++++--------------------------- client_wrapper.go | 6 ------ middleware.go | 8 -------- request.go | 8 -------- request_wrapper.go | 6 ------ 5 files changed, 20 insertions(+), 56 deletions(-) diff --git a/client.go b/client.go index b98eb44b..5386ed60 100644 --- a/client.go +++ b/client.go @@ -48,27 +48,26 @@ type Client struct { DebugLog bool AllowGetMethodPayload bool - trace bool - disableAutoReadResponse bool - commonErrorType reflect.Type - retryOption *retryOption - jsonMarshal func(v interface{}) ([]byte, error) - jsonUnmarshal func(data []byte, v interface{}) error - xmlMarshal func(v interface{}) ([]byte, error) - xmlUnmarshal func(data []byte, v interface{}) error - outputDirectory string - scheme string - log Logger - t *Transport - dumpOptions *DumpOptions - httpClient *http.Client - beforeRequest []RequestMiddleware - udBeforeRequest []RequestMiddleware - afterResponse []ResponseMiddleware - wrappedRoundTrip RoundTripper - responseBodyTransformer func(rawBody []byte, req *Request, resp *Response) (transformedBody []byte, err error) - unknownResultHandlerFunc func(resp *Response) error - resultStateCheckFunc func(resp *Response) ResultState + trace bool + disableAutoReadResponse bool + commonErrorType reflect.Type + retryOption *retryOption + jsonMarshal func(v interface{}) ([]byte, error) + jsonUnmarshal func(data []byte, v interface{}) error + xmlMarshal func(v interface{}) ([]byte, error) + xmlUnmarshal func(data []byte, v interface{}) error + outputDirectory string + scheme string + log Logger + t *Transport + dumpOptions *DumpOptions + httpClient *http.Client + beforeRequest []RequestMiddleware + udBeforeRequest []RequestMiddleware + afterResponse []ResponseMiddleware + wrappedRoundTrip RoundTripper + responseBodyTransformer func(rawBody []byte, req *Request, resp *Response) (transformedBody []byte, err error) + resultStateCheckFunc func(resp *Response) ResultState } // R create a new request. @@ -182,13 +181,6 @@ func (c *Client) SetCommonErrorResult(err interface{}) *Client { return c } -// SetCommonUnknownResultHandlerFunc set the response handler which will be executed when no -// error occurs, but Response.ResultState returns UnknownState. -func (c *Client) SetCommonUnknownResultHandlerFunc(fn func(resp *Response) error) *Client { - c.unknownResultHandlerFunc = fn - return c -} - // ResultState represents the state of the result. type ResultState int diff --git a/client_wrapper.go b/client_wrapper.go index aa366c9f..96907b63 100644 --- a/client_wrapper.go +++ b/client_wrapper.go @@ -36,12 +36,6 @@ func SetCommonErrorResult(err interface{}) *Client { return defaultClient.SetCommonErrorResult(err) } -// SetCommonUnknownResultHandlerFunc is a global wrapper methods which delegated -// to the default client's SetCommonUnknownResultHandlerFunc. -func SetCommonUnknownResultHandlerFunc(fn func(resp *Response) error) *Client { - return defaultClient.SetCommonUnknownResultHandlerFunc(fn) -} - // SetResultStateCheckFunc is a global wrapper methods which delegated // to the default client's SetCommonResultStateCheckFunc. func SetResultStateCheckFunc(fn func(resp *Response) ResultState) *Client { diff --git a/middleware.go b/middleware.go index 9eed2af6..b8865bdf 100644 --- a/middleware.go +++ b/middleware.go @@ -282,14 +282,6 @@ func parseResponseBody(c *Client, r *Response) (err error) { r.error = e } } - default: - handleUnknownResult := req.unknownResultHandlerFunc - if handleUnknownResult == nil { - handleUnknownResult = c.unknownResultHandlerFunc - } - if handleUnknownResult != nil { - return handleUnknownResult(r) - } } return } diff --git a/request.go b/request.go index 6d859277..4a48e9ac 100644 --- a/request.go +++ b/request.go @@ -66,7 +66,6 @@ type Request struct { trace *clientTrace dumpBuffer *bytes.Buffer responseReturnTime time.Time - unknownResultHandlerFunc func(resp *Response) error } type GetContentFunc func() (io.ReadCloser, error) @@ -388,13 +387,6 @@ func (r *Request) SetErrorResult(error interface{}) *Request { return r } -// SetUnknownResultHandlerFunc set the response handler which will be executed when no -// error occurs, but Response.ResultState returns UnknownState. -func (r *Request) SetUnknownResultHandlerFunc(fn func(resp *Response) error) *Request { - r.unknownResultHandlerFunc = fn - return r -} - // SetBearerAuthToken set bearer auth token for the request. func (r *Request) SetBearerAuthToken(token string) *Request { return r.SetHeader("Authorization", "Bearer "+token) diff --git a/request_wrapper.go b/request_wrapper.go index a0475686..daa1667a 100644 --- a/request_wrapper.go +++ b/request_wrapper.go @@ -102,12 +102,6 @@ func SetErrorResult(error interface{}) *Request { return defaultClient.R().SetErrorResult(error) } -// SetUnknownResultHandlerFunc is a global wrapper methods which delegated -// to the default client, create a request and SetUnknownResultHandlerFunc for request. -func SetUnknownResultHandlerFunc(fn func(resp *Response) error) *Request { - return defaultClient.R().SetUnknownResultHandlerFunc(fn) -} - // SetBearerAuthToken is a global wrapper methods which delegated // to the default client, create a request and SetBearerAuthToken for request. func SetBearerAuthToken(token string) *Request {