refactor: re-impl sdk3rd
This commit is contained in:
@@ -12,7 +12,7 @@ type CreateCertRequest struct {
|
||||
}
|
||||
|
||||
type CreateCertResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Id int64 `json:"id"`
|
||||
|
||||
@@ -13,7 +13,7 @@ type QueryCertDetailRequest struct {
|
||||
}
|
||||
|
||||
type QueryCertDetailResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Result *CertDetail `json:"result,omitempty"`
|
||||
|
||||
@@ -13,7 +13,7 @@ type QueryCertListRequest struct {
|
||||
}
|
||||
|
||||
type QueryCertListResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Results []*CertRecord `json:"result,omitempty"`
|
||||
|
||||
@@ -11,7 +11,7 @@ type QueryDomainDetailRequest struct {
|
||||
}
|
||||
|
||||
type QueryDomainDetailResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Domain string `json:"domain"`
|
||||
|
||||
@@ -13,7 +13,7 @@ type UpdateDomainRequest struct {
|
||||
}
|
||||
|
||||
type UpdateDomainResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UpdateDomain(req *UpdateDomainRequest) (*UpdateDomainResponse, error) {
|
||||
|
||||
@@ -32,18 +32,17 @@ func (c *Client) newRequest(method string, path string) (*resty.Request, error)
|
||||
return c.client.NewRequest(method, path)
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(request *resty.Request) (*resty.Response, error) {
|
||||
return c.client.DoRequest(request)
|
||||
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
||||
return c.client.DoRequest(req)
|
||||
}
|
||||
|
||||
func (c *Client) doRequestWithResult(request *resty.Request, result baseResultInterface) (*resty.Response, error) {
|
||||
response, err := c.client.DoRequestWithResult(request, result)
|
||||
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
||||
resp, err := c.client.DoRequestWithResult(req, res)
|
||||
if err == nil {
|
||||
statusCode := result.GetStatusCode()
|
||||
if statusCode != "" && statusCode != "100000" {
|
||||
return response, fmt.Errorf("sdkerr: api error, code='%s', message='%s', errorCode='%s', errorMessage='%s'", statusCode, result.GetMessage(), result.GetMessage(), result.GetErrorMessage())
|
||||
if tcode := res.GetStatusCode(); tcode != "" && tcode != "100000" {
|
||||
return resp, fmt.Errorf("sdkerr: api error, code='%s', message='%s', errorCode='%s', errorMessage='%s'", tcode, res.GetMessage(), res.GetMessage(), res.GetErrorMessage())
|
||||
}
|
||||
}
|
||||
|
||||
return response, err
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type baseResultInterface interface {
|
||||
type apiResponse interface {
|
||||
GetStatusCode() string
|
||||
GetMessage() string
|
||||
GetError() string
|
||||
GetErrorMessage() string
|
||||
}
|
||||
|
||||
type baseResult struct {
|
||||
type apiResponseBase struct {
|
||||
StatusCode json.RawMessage `json:"statusCode,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
@@ -21,7 +21,7 @@ type baseResult struct {
|
||||
RequestId *string `json:"requestId,omitempty"`
|
||||
}
|
||||
|
||||
func (r *baseResult) GetStatusCode() string {
|
||||
func (r *apiResponseBase) GetStatusCode() string {
|
||||
if r.StatusCode == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (r *baseResult) GetStatusCode() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *baseResult) GetMessage() string {
|
||||
func (r *apiResponseBase) GetMessage() string {
|
||||
if r.Message == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (r *baseResult) GetMessage() string {
|
||||
return *r.Message
|
||||
}
|
||||
|
||||
func (r *baseResult) GetError() string {
|
||||
func (r *apiResponseBase) GetError() string {
|
||||
if r.Error == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (r *baseResult) GetError() string {
|
||||
return *r.Error
|
||||
}
|
||||
|
||||
func (r *baseResult) GetErrorMessage() string {
|
||||
func (r *apiResponseBase) GetErrorMessage() string {
|
||||
if r.ErrorMessage == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (r *baseResult) GetErrorMessage() string {
|
||||
return *r.ErrorMessage
|
||||
}
|
||||
|
||||
var _ baseResultInterface = (*baseResult)(nil)
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
|
||||
type CertRecord struct {
|
||||
Id int64 `json:"id"`
|
||||
|
||||
Reference in New Issue
Block a user