From b15bf8ef9817b216d415eebd70d804ec7ea6e0e1 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Fri, 16 May 2025 13:56:45 +0800 Subject: [PATCH] refactor: clean code --- internal/pkg/sdk3rd/1panel/client.go | 4 ++-- internal/pkg/sdk3rd/baishan/client.go | 4 ++-- internal/pkg/sdk3rd/btpanel/client.go | 4 ++-- internal/pkg/sdk3rd/bunny/client.go | 2 +- internal/pkg/sdk3rd/cachefly/client.go | 4 ++-- internal/pkg/sdk3rd/cdnfly/client.go | 4 ++-- internal/pkg/sdk3rd/dnsla/client.go | 4 ++-- .../applications/v7/edgio_client.go | 4 ++-- internal/pkg/sdk3rd/gname/client.go | 4 ++-- internal/pkg/sdk3rd/goedge/api.go | 2 +- internal/pkg/sdk3rd/goedge/client.go | 4 ++-- internal/pkg/sdk3rd/netlify/client.go | 4 ++-- internal/pkg/sdk3rd/rainyun/client.go | 4 ++-- internal/pkg/sdk3rd/safeline/client.go | 4 ++-- internal/pkg/sdk3rd/upyun/console/api.go | 2 +- internal/pkg/sdk3rd/upyun/console/client.go | 6 +++--- internal/pkg/sdk3rd/wangsu/openapi/client.go | 4 ++-- 17 files changed, 32 insertions(+), 32 deletions(-) diff --git a/internal/pkg/sdk3rd/1panel/client.go b/internal/pkg/sdk3rd/1panel/client.go index 0afbe2a5..e8946bae 100644 --- a/internal/pkg/sdk3rd/1panel/client.go +++ b/internal/pkg/sdk3rd/1panel/client.go @@ -79,7 +79,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("1panel api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("1panel api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("1panel api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -95,7 +95,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("1panel api error: failed to parse response: %w", err) + return fmt.Errorf("1panel api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode/100 != 2 { return fmt.Errorf("1panel api error: code='%d', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/baishan/client.go b/internal/pkg/sdk3rd/baishan/client.go index 408bcbc9..81790a21 100644 --- a/internal/pkg/sdk3rd/baishan/client.go +++ b/internal/pkg/sdk3rd/baishan/client.go @@ -75,7 +75,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("baishan api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("baishan api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("baishan api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -91,7 +91,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("baishan api error: failed to parse response: %w", err) + return fmt.Errorf("baishan api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode != 0 { return fmt.Errorf("baishan api error: code='%d', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/btpanel/client.go b/internal/pkg/sdk3rd/btpanel/client.go index 781e9a75..e09eed13 100644 --- a/internal/pkg/sdk3rd/btpanel/client.go +++ b/internal/pkg/sdk3rd/btpanel/client.go @@ -86,7 +86,7 @@ func (c *Client) sendRequest(path string, params interface{}) (*resty.Response, if err != nil { return resp, fmt.Errorf("baota api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("baota api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("baota api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -99,7 +99,7 @@ func (c *Client) sendRequestWithResult(path string, params interface{}, result B } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("baota api error: failed to parse response: %w", err) + return fmt.Errorf("baota api error: failed to unmarshal response: %w", err) } else if errstatus := result.GetStatus(); errstatus != nil && !*errstatus { if result.GetMessage() == nil { return fmt.Errorf("baota api error: unknown error") diff --git a/internal/pkg/sdk3rd/bunny/client.go b/internal/pkg/sdk3rd/bunny/client.go index 2b1ed4d1..0f0dbea5 100644 --- a/internal/pkg/sdk3rd/bunny/client.go +++ b/internal/pkg/sdk3rd/bunny/client.go @@ -59,7 +59,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("bunny api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("bunny api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("bunny api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil diff --git a/internal/pkg/sdk3rd/cachefly/client.go b/internal/pkg/sdk3rd/cachefly/client.go index b1777ea9..37a82ccc 100644 --- a/internal/pkg/sdk3rd/cachefly/client.go +++ b/internal/pkg/sdk3rd/cachefly/client.go @@ -59,7 +59,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("cachefly api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("cachefly api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("cachefly api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -75,7 +75,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("cachefly api error: failed to parse response: %w", err) + return fmt.Errorf("cachefly api error: failed to unmarshal response: %w", err) } return nil diff --git a/internal/pkg/sdk3rd/cdnfly/client.go b/internal/pkg/sdk3rd/cdnfly/client.go index 0061e363..5d80395c 100644 --- a/internal/pkg/sdk3rd/cdnfly/client.go +++ b/internal/pkg/sdk3rd/cdnfly/client.go @@ -71,7 +71,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("cdnfly api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("cdnfly api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("cdnfly api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -87,7 +87,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("cdnfly api error: failed to parse response: %w", err) + return fmt.Errorf("cdnfly api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode != "" && errcode != "0" { return fmt.Errorf("cdnfly api error: code='%s', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/dnsla/client.go b/internal/pkg/sdk3rd/dnsla/client.go index 7dfbd00a..a0659011 100644 --- a/internal/pkg/sdk3rd/dnsla/client.go +++ b/internal/pkg/sdk3rd/dnsla/client.go @@ -60,7 +60,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("dnsla api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("dnsla api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("dnsla api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -76,7 +76,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("dnsla api error: failed to parse response: %w", err) + return fmt.Errorf("dnsla api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode/100 != 2 { return fmt.Errorf("dnsla api error: code='%d', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/edgio/edgio-api@v0.0.0-workspace/applications/v7/edgio_client.go b/internal/pkg/sdk3rd/edgio/edgio-api@v0.0.0-workspace/applications/v7/edgio_client.go index fb7b7cf7..02ded6fd 100644 --- a/internal/pkg/sdk3rd/edgio/edgio-api@v0.0.0-workspace/applications/v7/edgio_client.go +++ b/internal/pkg/sdk3rd/edgio/edgio-api@v0.0.0-workspace/applications/v7/edgio_client.go @@ -140,7 +140,7 @@ func (c *EdgioClient) GetProperties(page int, pageSize int, organizationID strin } if resp.IsError() { - return nil, fmt.Errorf("unexpected status code for getProperties: %d, %s", resp.StatusCode(), resp.Body()) + return nil, fmt.Errorf("unexpected status code for getProperties: %d, %s", resp.StatusCode(), resp.String()) } return &propertiesResp, nil @@ -512,7 +512,7 @@ func (c *EdgioClient) UploadCdnConfiguration(config *dtos.CDNConfiguration) (*dt } if resp.IsError() { - return nil, fmt.Errorf("unexpected status code for uploadCdnConfiguration: %d, %s", resp.StatusCode(), resp.Body()) + return nil, fmt.Errorf("unexpected status code for uploadCdnConfiguration: %d, %s", resp.StatusCode(), resp.String()) } return &response, nil diff --git a/internal/pkg/sdk3rd/gname/client.go b/internal/pkg/sdk3rd/gname/client.go index 9424e8ec..ef00e699 100644 --- a/internal/pkg/sdk3rd/gname/client.go +++ b/internal/pkg/sdk3rd/gname/client.go @@ -82,7 +82,7 @@ func (c *Client) sendRequest(path string, params interface{}) (*resty.Response, if err != nil { return resp, fmt.Errorf("gname api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("gname api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("gname api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -95,7 +95,7 @@ func (c *Client) sendRequestWithResult(path string, params interface{}, result B } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("gname api error: failed to parse response: %w", err) + return fmt.Errorf("gname api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode != 1 { return fmt.Errorf("gname api error: code='%d', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/goedge/api.go b/internal/pkg/sdk3rd/goedge/api.go index c217e8ae..f0f60944 100644 --- a/internal/pkg/sdk3rd/goedge/api.go +++ b/internal/pkg/sdk3rd/goedge/api.go @@ -20,7 +20,7 @@ func (c *Client) getAccessToken() error { resp := &getAPIAccessTokenResponse{} if err := json.Unmarshal(res.Body(), &resp); err != nil { - return fmt.Errorf("goedge api error: failed to parse response: %w", err) + return fmt.Errorf("goedge api error: failed to unmarshal response: %w", err) } else if resp.GetCode() != 200 { return fmt.Errorf("goedge get access token failed: code: %d, message: %s", resp.GetCode(), resp.GetMessage()) } diff --git a/internal/pkg/sdk3rd/goedge/client.go b/internal/pkg/sdk3rd/goedge/client.go index c42b798b..e0a2ce49 100644 --- a/internal/pkg/sdk3rd/goedge/client.go +++ b/internal/pkg/sdk3rd/goedge/client.go @@ -78,7 +78,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("goedge api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("goedge api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("goedge api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -94,7 +94,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("goedge api error: failed to parse response: %w", err) + return fmt.Errorf("goedge api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode != 200 { return fmt.Errorf("goedge api error: code='%d', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/netlify/client.go b/internal/pkg/sdk3rd/netlify/client.go index 5f8bc6c2..e3110077 100644 --- a/internal/pkg/sdk3rd/netlify/client.go +++ b/internal/pkg/sdk3rd/netlify/client.go @@ -72,7 +72,7 @@ func (c *Client) sendRequest(method string, path string, queryParams interface{} if err != nil { return resp, fmt.Errorf("netlify api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("netlify api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("netlify api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -88,7 +88,7 @@ func (c *Client) sendRequestWithResult(method string, path string, queryParams i } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("netlify api error: failed to parse response: %w", err) + return fmt.Errorf("netlify api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode != 0 { return fmt.Errorf("netlify api error: code='%d', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/rainyun/client.go b/internal/pkg/sdk3rd/rainyun/client.go index 0ead39cd..eb34efd1 100644 --- a/internal/pkg/sdk3rd/rainyun/client.go +++ b/internal/pkg/sdk3rd/rainyun/client.go @@ -49,7 +49,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("rainyun api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("rainyun api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("rainyun api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -65,7 +65,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("rainyun api error: failed to parse response: %w", err) + return fmt.Errorf("rainyun api error: failed to unmarshal response: %w", err) } else if errcode := result.GetCode(); errcode/100 != 2 { return fmt.Errorf("rainyun api error: code='%d', message='%s'", errcode, result.GetMessage()) } diff --git a/internal/pkg/sdk3rd/safeline/client.go b/internal/pkg/sdk3rd/safeline/client.go index 4705d74e..0412514c 100644 --- a/internal/pkg/sdk3rd/safeline/client.go +++ b/internal/pkg/sdk3rd/safeline/client.go @@ -47,7 +47,7 @@ func (c *Client) sendRequest(path string, params interface{}) (*resty.Response, if err != nil { return resp, fmt.Errorf("safeline api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("safeline api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("safeline api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -63,7 +63,7 @@ func (c *Client) sendRequestWithResult(path string, params interface{}, result B } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("safeline api error: failed to parse response: %w", err) + return fmt.Errorf("safeline api error: failed to unmarshal response: %w", err) } else if errcode := result.GetErrCode(); errcode != nil && *errcode != "" { if result.GetErrMsg() == nil { return fmt.Errorf("safeline api error: code='%s'", *errcode) diff --git a/internal/pkg/sdk3rd/upyun/console/api.go b/internal/pkg/sdk3rd/upyun/console/api.go index 28ccd734..32b4626e 100644 --- a/internal/pkg/sdk3rd/upyun/console/api.go +++ b/internal/pkg/sdk3rd/upyun/console/api.go @@ -16,7 +16,7 @@ func (c *Client) getCookie() error { resp := &signinResponse{} if err := json.Unmarshal(res.Body(), &resp); err != nil { - return fmt.Errorf("upyun api error: failed to parse response: %w", err) + return fmt.Errorf("upyun api error: failed to unmarshal response: %w", err) } else if !resp.Data.Result { return errors.New("upyun console signin failed") } diff --git a/internal/pkg/sdk3rd/upyun/console/client.go b/internal/pkg/sdk3rd/upyun/console/client.go index 90d74bc3..7a7ea7de 100644 --- a/internal/pkg/sdk3rd/upyun/console/client.go +++ b/internal/pkg/sdk3rd/upyun/console/client.go @@ -65,7 +65,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r if err != nil { return resp, fmt.Errorf("upyun api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("upyun api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("upyun api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -81,12 +81,12 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf } if err := json.Unmarshal(resp.Body(), &result); err != nil { - return fmt.Errorf("upyun api error: failed to parse response: %w", err) + return fmt.Errorf("upyun api error: failed to unmarshal response: %w", err) } tresp := &baseResponse{} if err := json.Unmarshal(resp.Body(), &tresp); err != nil { - return fmt.Errorf("upyun api error: failed to parse response: %w", err) + return fmt.Errorf("upyun api error: failed to unmarshal response: %w", err) } else if tdata := tresp.GetData(); tdata == nil { return fmt.Errorf("upyun api error: empty data") } else if errcode := tdata.GetErrorCode(); errcode > 0 { diff --git a/internal/pkg/sdk3rd/wangsu/openapi/client.go b/internal/pkg/sdk3rd/wangsu/openapi/client.go index d63c20c7..95d17bb0 100644 --- a/internal/pkg/sdk3rd/wangsu/openapi/client.go +++ b/internal/pkg/sdk3rd/wangsu/openapi/client.go @@ -162,7 +162,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}, con if err != nil { return resp, fmt.Errorf("wangsu api error: failed to send request: %w", err) } else if resp.IsError() { - return resp, fmt.Errorf("wangsu api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body()) + return resp, fmt.Errorf("wangsu api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String()) } return resp, nil @@ -181,7 +181,7 @@ func (c *Client) SendRequestWithResult(method string, path string, params interf respBody := resp.Body() if len(respBody) != 0 { if err := json.Unmarshal(respBody, &result); err != nil { - return resp, fmt.Errorf("wangsu api error: failed to parse response: %w", err) + return resp, fmt.Errorf("wangsu api error: failed to unmarshal response: %w", err) } }