refactor: clean code
This commit is contained in:
49
internal/pkg/vendors/upyun-sdk/console/api.go
vendored
49
internal/pkg/vendors/upyun-sdk/console/api.go
vendored
@@ -33,12 +33,9 @@ func (c *Client) UploadHttpsCertificate(req *UploadHttpsCertificateRequest) (*Up
|
||||
}
|
||||
}
|
||||
|
||||
resp := UploadHttpsCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UploadHttpsCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsCertificateManager(certificateId string) (*GetHttpsCertificateManagerResponse, error) {
|
||||
@@ -48,13 +45,10 @@ func (c *Client) GetHttpsCertificateManager(certificateId string) (*GetHttpsCert
|
||||
}
|
||||
}
|
||||
|
||||
req := GetHttpsCertificateManagerRequest{CertificateId: certificateId}
|
||||
resp := GetHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/certificate/manager/", &req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
req := &GetHttpsCertificateManagerRequest{CertificateId: certificateId}
|
||||
resp := &GetHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/certificate/manager/", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) UpdateHttpsCertificateManager(req *UpdateHttpsCertificateManagerRequest) (*UpdateHttpsCertificateManagerResponse, error) {
|
||||
@@ -64,12 +58,9 @@ func (c *Client) UpdateHttpsCertificateManager(req *UpdateHttpsCertificateManage
|
||||
}
|
||||
}
|
||||
|
||||
resp := UpdateHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/manager", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &UpdateHttpsCertificateManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/certificate/manager", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetHttpsServiceManager(domain string) (*GetHttpsServiceManagerResponse, error) {
|
||||
@@ -79,13 +70,10 @@ func (c *Client) GetHttpsServiceManager(domain string) (*GetHttpsServiceManagerR
|
||||
}
|
||||
}
|
||||
|
||||
req := GetHttpsServiceManagerRequest{Domain: domain}
|
||||
resp := GetHttpsServiceManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/services/manager", &req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
req := &GetHttpsServiceManagerRequest{Domain: domain}
|
||||
resp := &GetHttpsServiceManagerResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/api/https/services/manager", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) MigrateHttpsDomain(req *MigrateHttpsDomainRequest) (*MigrateHttpsDomainResponse, error) {
|
||||
@@ -95,10 +83,7 @@ func (c *Client) MigrateHttpsDomain(req *MigrateHttpsDomainRequest) (*MigrateHtt
|
||||
}
|
||||
}
|
||||
|
||||
resp := MigrateHttpsDomainResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/migrate/domain", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &MigrateHttpsDomainResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/api/https/migrate/domain", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -60,12 +60,11 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
SetBody(params)
|
||||
}
|
||||
|
||||
req = req.SetDebug(true)
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("upyun api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("upyun api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("upyun api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("upyun api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
14
internal/pkg/vendors/upyun-sdk/console/models.go
vendored
14
internal/pkg/vendors/upyun-sdk/console/models.go
vendored
@@ -41,10 +41,10 @@ type signinRequest struct {
|
||||
|
||||
type signinResponse struct {
|
||||
baseResponse
|
||||
Data struct {
|
||||
Data *struct {
|
||||
baseResponseData
|
||||
Result bool `json:"result"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type UploadHttpsCertificateRequest struct {
|
||||
@@ -62,7 +62,7 @@ type UploadHttpsCertificateResponse struct {
|
||||
CommonName string `json:"commonName"`
|
||||
Serial string `json:"serial"`
|
||||
} `json:"result"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type GetHttpsCertificateManagerRequest struct {
|
||||
@@ -76,7 +76,7 @@ type GetHttpsCertificateManagerResponse struct {
|
||||
AuthenticateNum int32 `json:"authenticate_num"`
|
||||
AuthenticateDomains []string `json:"authenticate_domain"`
|
||||
Domains []HttpsCertificateManagerDomain `json:"domains"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type HttpsCertificateManagerDomain struct {
|
||||
@@ -98,7 +98,7 @@ type UpdateHttpsCertificateManagerResponse struct {
|
||||
Data *struct {
|
||||
baseResponseData
|
||||
Status bool `json:"status"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type GetHttpsServiceManagerRequest struct {
|
||||
@@ -111,7 +111,7 @@ type GetHttpsServiceManagerResponse struct {
|
||||
baseResponseData
|
||||
Status int `json:"status"`
|
||||
Domains []HttpsServiceManagerDomain `json:"result"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type HttpsServiceManagerDomain struct {
|
||||
@@ -137,5 +137,5 @@ type MigrateHttpsDomainResponse struct {
|
||||
Data *struct {
|
||||
baseResponseData
|
||||
Status bool `json:"status"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user