mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-19 01:41:55 +08:00
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package cms
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/go-resty/resty/v2"
|
|
"github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/openapi"
|
|
)
|
|
|
|
const endpoint = "https://ccms-global.ctapi.ctyun.cn"
|
|
|
|
type Client struct {
|
|
client *openapi.Client
|
|
}
|
|
|
|
func NewClient(accessKeyId, secretAccessKey string) (*Client, error) {
|
|
client, err := openapi.NewClient(endpoint, accessKeyId, secretAccessKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Client{client: client}, nil
|
|
}
|
|
|
|
func (c *Client) SetTimeout(timeout time.Duration) *Client {
|
|
c.client.SetTimeout(timeout)
|
|
return c
|
|
}
|
|
|
|
func (c *Client) newRequest(method string, path string) (*resty.Request, error) {
|
|
return c.client.NewRequest(method, path)
|
|
}
|
|
|
|
func (c *Client) doRequest(req *resty.Request) (*resty.Response, error) {
|
|
return c.client.DoRequest(req)
|
|
}
|
|
|
|
func (c *Client) doRequestWithResult(req *resty.Request, res apiResponse) (*resty.Response, error) {
|
|
resp, err := c.client.DoRequestWithResult(req, res)
|
|
if err == nil {
|
|
statusCode := res.GetStatusCode()
|
|
errorCode := res.GetError()
|
|
if (statusCode != "" && statusCode != "200") || errorCode != "" {
|
|
return resp, fmt.Errorf("sdkerr: api error, code='%s', message='%s', errorCode='%s', errorMessage='%s'", statusCode, res.GetMessage(), res.GetMessage(), res.GetErrorMessage())
|
|
}
|
|
}
|
|
|
|
return resp, err
|
|
}
|