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"`
|
||||
|
||||
@@ -11,7 +11,7 @@ type GetDomainConfigRequest struct {
|
||||
}
|
||||
|
||||
type GetDomainConfigResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Domain string `json:"domain"`
|
||||
@@ -35,13 +35,7 @@ func (c *Client) GetDomainConfigWithContext(ctx context.Context, req *GetDomainC
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if req.Domain != nil {
|
||||
httpreq.SetQueryParam("domain", *req.Domain)
|
||||
}
|
||||
if req.ProductCode != nil {
|
||||
httpreq.SetQueryParam("product_code", *req.ProductCode)
|
||||
}
|
||||
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ type ListCertsRequest struct {
|
||||
}
|
||||
|
||||
type ListCertsResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Results []*CertRecord `json:"result,omitempty"`
|
||||
|
||||
@@ -15,7 +15,7 @@ type ModifyDomainConfigRequest struct {
|
||||
}
|
||||
|
||||
type ModifyDomainConfigResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) ModifyDomainConfig(req *ModifyDomainConfigRequest) (*ModifyDomainConfigResponse, error) {
|
||||
|
||||
@@ -13,7 +13,7 @@ type QueryCertRequest struct {
|
||||
}
|
||||
|
||||
type QueryCertResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Result *CertDetail `json:"result,omitempty"`
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -12,7 +12,7 @@ type QueryDomainDetailRequest struct {
|
||||
}
|
||||
|
||||
type QueryDomainDetailResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Domain string `json:"domain"`
|
||||
|
||||
@@ -12,7 +12,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"`
|
||||
|
||||
@@ -14,7 +14,7 @@ type GetCertificateListRequest struct {
|
||||
}
|
||||
|
||||
type GetCertificateListResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
List []*CertificateRecord `json:"list,omitempty"`
|
||||
|
||||
@@ -16,7 +16,7 @@ type UploadCertificateRequest struct {
|
||||
}
|
||||
|
||||
type UploadCertificateResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) UploadCertificate(req *UploadCertificateRequest) (*UploadCertificateResponse, error) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -17,7 +17,7 @@ type AddRecordRequest struct {
|
||||
}
|
||||
|
||||
type AddRecordResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
RecordId int32 `json:"recordId"`
|
||||
|
||||
@@ -10,7 +10,7 @@ type DeleteRecordRequest struct {
|
||||
}
|
||||
|
||||
type DeleteRecordResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
}
|
||||
|
||||
func (c *Client) DeleteRecord(req *DeleteRecordRequest) (*DeleteRecordResponse, error) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package dns
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type QueryRecordListRequest struct {
|
||||
@@ -15,7 +16,7 @@ type QueryRecordListRequest struct {
|
||||
}
|
||||
|
||||
type QueryRecordListResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Records []*DnsRecord `json:"records,omitempty"`
|
||||
@@ -31,6 +32,25 @@ func (c *Client) QueryRecordListWithContext(ctx context.Context, req *QueryRecor
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if req.Domain != nil {
|
||||
httpreq.SetQueryParam("domain", *req.Domain)
|
||||
}
|
||||
if req.Host != nil {
|
||||
httpreq.SetQueryParam("host", *req.Host)
|
||||
}
|
||||
if req.Type != nil {
|
||||
httpreq.SetQueryParam("type", *req.Type)
|
||||
}
|
||||
if req.LineCode != nil {
|
||||
httpreq.SetQueryParam("lineCode", *req.LineCode)
|
||||
}
|
||||
if req.Value != nil {
|
||||
httpreq.SetQueryParam("value", *req.Value)
|
||||
}
|
||||
if req.State != nil {
|
||||
httpreq.SetQueryParam("state", strconv.Itoa(int(*req.State)))
|
||||
}
|
||||
|
||||
httpreq.SetBody(req)
|
||||
httpreq.SetContext(ctx)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ type UpdateRecordRequest struct {
|
||||
}
|
||||
|
||||
type UpdateRecordResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
RecordId int32 `json:"recordId"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 DnsRecord struct {
|
||||
RecordId int32 `json:"recordId"`
|
||||
|
||||
@@ -16,7 +16,7 @@ type CreateCertificateRequest struct {
|
||||
}
|
||||
|
||||
type CreateCertificateResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
ID string `json:"id"`
|
||||
|
||||
@@ -14,7 +14,7 @@ type ListCertificatesRequest struct {
|
||||
}
|
||||
|
||||
type ListCertificatesResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj []*CertificateRecord `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type ListListenersRequest struct {
|
||||
}
|
||||
|
||||
type ListListenersResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj []*ListenerRecord `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ type ShowListenerRequest struct {
|
||||
}
|
||||
|
||||
type ShowListenerResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj []*ListenerRecord `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ type UpdateListenerRequest struct {
|
||||
}
|
||||
|
||||
type UpdateListenerResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj []*ListenerRecord `json:"returnObj,omitempty"`
|
||||
}
|
||||
|
||||
@@ -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" && statusCode != "800") || (errorCode != "" && errorCode != "SUCCESS") {
|
||||
return response, fmt.Errorf("sdkerr: api error, code='%s', message='%s', errorCode='%s', description='%s'", statusCode, result.GetMessage(), result.GetMessage(), result.GetDescription())
|
||||
return resp, fmt.Errorf("sdkerr: api error, code='%s', message='%s', errorCode='%s', description='%s'", statusCode, res.GetMessage(), res.GetMessage(), res.GetDescription())
|
||||
}
|
||||
}
|
||||
|
||||
return response, err
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type baseResultInterface interface {
|
||||
type apiResponse interface {
|
||||
GetStatusCode() string
|
||||
GetMessage() string
|
||||
GetError() string
|
||||
GetDescription() 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) GetDescription() string {
|
||||
func (r *apiResponseBase) GetDescription() string {
|
||||
if r.Description == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (r *baseResult) GetDescription() string {
|
||||
return *r.Description
|
||||
}
|
||||
|
||||
var _ baseResultInterface = (*baseResult)(nil)
|
||||
var _ apiResponse = (*apiResponseBase)(nil)
|
||||
|
||||
type CertificateRecord struct {
|
||||
ID string `json:"ID"`
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -12,7 +12,7 @@ type QueryDomainDetailRequest struct {
|
||||
}
|
||||
|
||||
type QueryDomainDetailResponse struct {
|
||||
baseResult
|
||||
apiResponseBase
|
||||
|
||||
ReturnObj *struct {
|
||||
Domain string `json:"domain"`
|
||||
|
||||
@@ -12,7 +12,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"`
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -28,10 +28,10 @@ func NewClient(endpoint, accessKeyId, secretAccessKey string) (*Client, error) {
|
||||
return nil, fmt.Errorf("sdkerr: invalid endpoint: %w", err)
|
||||
}
|
||||
if accessKeyId == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset accessKey")
|
||||
return nil, fmt.Errorf("sdkerr: unset accessKeyId")
|
||||
}
|
||||
if secretAccessKey == "" {
|
||||
return nil, fmt.Errorf("sdkerr: unset secretKey")
|
||||
return nil, fmt.Errorf("sdkerr: unset secretAccessKey")
|
||||
}
|
||||
|
||||
client := resty.New().
|
||||
@@ -102,9 +102,7 @@ func NewClient(endpoint, accessKeyId, secretAccessKey string) (*Client, error) {
|
||||
return nil
|
||||
})
|
||||
|
||||
return &Client{
|
||||
client: client,
|
||||
}, nil
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
||||
@@ -126,15 +124,15 @@ func (c *Client) NewRequest(method string, path string) (*resty.Request, error)
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) DoRequest(request *resty.Request) (*resty.Response, error) {
|
||||
if request == nil {
|
||||
func (c *Client) DoRequest(req *resty.Request) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
// WARN:
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` here.
|
||||
// PLEASE DO NOT USE `req.SetResult` or `req.SetError` HERE! USE `doRequestWithResult` INSTEAD.
|
||||
|
||||
resp, err := request.Send()
|
||||
resp, err := req.Send()
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
@@ -144,24 +142,24 @@ func (c *Client) DoRequest(request *resty.Request) (*resty.Response, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) DoRequestWithResult(request *resty.Request, result any) (*resty.Response, error) {
|
||||
if request == nil {
|
||||
func (c *Client) DoRequestWithResult(req *resty.Request, res any) (*resty.Response, error) {
|
||||
if req == nil {
|
||||
return nil, fmt.Errorf("sdkerr: nil request")
|
||||
}
|
||||
|
||||
response, err := c.DoRequest(request)
|
||||
resp, err := c.DoRequest(req)
|
||||
if err != nil {
|
||||
if response != nil {
|
||||
json.Unmarshal(response.Body(), &result)
|
||||
if resp != nil {
|
||||
json.Unmarshal(resp.Body(), &res)
|
||||
}
|
||||
return response, err
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(response.Body()) != 0 {
|
||||
if err := json.Unmarshal(response.Body(), &result); err != nil {
|
||||
return response, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
if len(resp.Body()) != 0 {
|
||||
if err := json.Unmarshal(resp.Body(), &res); err != nil {
|
||||
return resp, fmt.Errorf("sdkerr: failed to unmarshal response: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return response, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user