mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 05:29:51 +00:00
refactor: clean code
This commit is contained in:
parent
dd2087b101
commit
b15bf8ef98
@ -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())
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user