refactor: clean code

This commit is contained in:
Fu Diwei
2025-05-20 14:15:17 +08:00
parent 7a663d31cb
commit 4ad08d983a
27 changed files with 169 additions and 247 deletions

View File

@@ -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() {