refactor: re-impl sdk3rd

This commit is contained in:
Fu Diwei
2025-06-17 10:39:39 +08:00
parent 9421da2cde
commit 299a722aa9
280 changed files with 6923 additions and 4658 deletions

View File

@@ -14,7 +14,7 @@ type GetCertificateListRequest struct {
}
type GetCertificateListResponse struct {
baseResult
apiResponseBase
ReturnObj *struct {
List []*CertificateRecord `json:"list,omitempty"`

View File

@@ -16,7 +16,7 @@ type UploadCertificateRequest struct {
}
type UploadCertificateResponse struct {
baseResult
apiResponseBase
}
func (c *Client) UploadCertificate(req *UploadCertificateRequest) (*UploadCertificateResponse, error) {

View File

@@ -32,19 +32,19 @@ 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()
errorCode := result.GetError()
statusCode := res.GetStatusCode()
errorCode := res.GetError()
if (statusCode != "" && statusCode != "200") || errorCode != "" {
return response, fmt.Errorf("sdkerr: api error, code='%s', message='%s', errorCode='%s', errorMessage='%s'", statusCode, result.GetMessage(), result.GetMessage(), result.GetErrorMessage())
return resp, fmt.Errorf("sdkerr: api error, code='%s', message='%s', errorCode='%s', errorMessage='%s'", statusCode, res.GetMessage(), res.GetMessage(), res.GetErrorMessage())
}
}
return response, err
return resp, err
}

View File

@@ -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 CertificateRecord struct {
Id string `json:"id"`