refactor: clean code
This commit is contained in:
27
internal/pkg/vendors/baishan-sdk/api.go
vendored
27
internal/pkg/vendors/baishan-sdk/api.go
vendored
@@ -5,28 +5,19 @@ import (
|
||||
)
|
||||
|
||||
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
||||
resp := CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/certificate", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &CreateCertificateResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/certificate", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) {
|
||||
resp := GetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/v2/domain/config", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &GetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodGet, "/v2/domain/config", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Client) SetDomainConfig(req *SetDomainConfigRequest) (*SetDomainConfigResponse, error) {
|
||||
resp := SetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/config", req, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
resp := &SetDomainConfigResponse{}
|
||||
err := c.sendRequestWithResult(http.MethodPost, "/v2/domain/config", req, resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
6
internal/pkg/vendors/baishan-sdk/client.go
vendored
6
internal/pkg/vendors/baishan-sdk/client.go
vendored
@@ -63,7 +63,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
req = req.
|
||||
SetQueryParam("token", c.apiToken).
|
||||
SetQueryParamsFromValues(qs).SetDebug(true)
|
||||
SetQueryParamsFromValues(qs)
|
||||
} else {
|
||||
req = req.
|
||||
SetHeader("Content-Type", "application/json").
|
||||
@@ -73,9 +73,9 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("baishan api error: failed to send request: %w", err)
|
||||
return resp, fmt.Errorf("baishan api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return nil, fmt.Errorf("baishan api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("baishan api error: unexpected status code: %d, %s", resp.StatusCode(), resp.Body())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
20
internal/pkg/vendors/baishan-sdk/models.go
vendored
20
internal/pkg/vendors/baishan-sdk/models.go
vendored
@@ -6,16 +6,22 @@ type BaseResponse interface {
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Code *int `json:"code,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetCode() int {
|
||||
return r.Code
|
||||
if r.Code != nil {
|
||||
return *r.Code
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMessage() string {
|
||||
return r.Message
|
||||
if r.Message != nil {
|
||||
return *r.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type CreateCertificateRequest struct {
|
||||
@@ -26,7 +32,7 @@ type CreateCertificateRequest struct {
|
||||
|
||||
type CreateCertificateResponse struct {
|
||||
baseResponse
|
||||
Data *DomainCertificate `json:"data"`
|
||||
Data *DomainCertificate `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type GetDomainConfigRequest struct {
|
||||
@@ -39,7 +45,7 @@ type GetDomainConfigResponse struct {
|
||||
Data []*struct {
|
||||
Domain string `json:"domain"`
|
||||
Config *DomainConfig `json:"config"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type SetDomainConfigRequest struct {
|
||||
@@ -51,7 +57,7 @@ type SetDomainConfigResponse struct {
|
||||
baseResponse
|
||||
Data *struct {
|
||||
Config *DomainConfig `json:"config"`
|
||||
} `json:"data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type DomainCertificate struct {
|
||||
|
||||
Reference in New Issue
Block a user