refactor: clean code
This commit is contained in:
@@ -134,8 +134,6 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
||||
|
||||
func (c *Client) sendRequest(method string, path string, params interface{}, configureReq ...func(req *resty.Request)) (*resty.Response, error) {
|
||||
req := c.client.R()
|
||||
req.Method = method
|
||||
req.URL = path
|
||||
if strings.EqualFold(method, http.MethodGet) {
|
||||
qs := make(map[string]string)
|
||||
if params != nil {
|
||||
@@ -151,7 +149,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}, con
|
||||
|
||||
req = req.SetQueryParams(qs)
|
||||
} else {
|
||||
req = req.SetBody(params)
|
||||
req = req.SetHeader("Content-Type", "application/json").SetBody(params)
|
||||
}
|
||||
|
||||
if configureReq != nil {
|
||||
@@ -160,7 +158,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}, con
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := req.Send()
|
||||
resp, err := req.Execute(method, path)
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("wangsu api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
|
||||
Reference in New Issue
Block a user