refactor: clean code

This commit is contained in:
Fu Diwei
2025-03-23 10:19:24 +08:00
parent 445541c38f
commit 12102ef641
28 changed files with 166 additions and 245 deletions

View File

@@ -5,10 +5,7 @@ import (
)
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
resp := CreateCertificateResponse{}
err := c.sendRequestWithResult(http.MethodPost, "/certificates", req, &resp)
if err != nil {
return nil, err
}
return &resp, nil
resp := &CreateCertificateResponse{}
err := c.sendRequestWithResult(http.MethodPost, "/certificates", req, resp)
return resp, err
}

View File

@@ -57,9 +57,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
resp, err := req.Send()
if err != nil {
return nil, fmt.Errorf("cachefly api error: failed to send request: %w", err)
return resp, fmt.Errorf("cachefly api error: failed to send request: %w", err)
} else if resp.IsError() {
return nil, fmt.Errorf("cachefly api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
return resp, fmt.Errorf("cachefly api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
}
return resp, nil

View File

@@ -1,15 +1,18 @@
package cacheflysdk
type BaseResponse interface {
GetMessage() *string
GetMessage() string
}
type baseResponse struct {
Message *string `json:"message,omitempty"`
}
func (r *baseResponse) GetMessage() *string {
return r.Message
func (r *baseResponse) GetMessage() string {
if r.Message != nil {
return *r.Message
}
return ""
}
type CreateCertificateRequest struct {