refactor: reimpl 3rd sdks

This commit is contained in:
Fu Diwei
2025-02-19 21:55:38 +08:00
parent 688a013d73
commit 469c24751e
16 changed files with 131 additions and 189 deletions

View File

@@ -1,18 +1,10 @@
package safelinesdk
import (
"encoding/json"
)
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
params := make(map[string]any)
jsonData, _ := json.Marshal(req)
json.Unmarshal(jsonData, &params)
result := UpdateCertificateResponse{}
err := c.sendRequestWithResult("/api/open/cert", params, &result)
resp := UpdateCertificateResponse{}
err := c.sendRequestWithResult("/api/open/cert", req, &resp)
if err != nil {
return nil, err
}
return &result, nil
return &resp, nil
}

View File

@@ -31,11 +31,7 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
return c
}
func (c *Client) sendRequest(path string, params map[string]any) (*resty.Response, error) {
if params == nil {
params = make(map[string]any)
}
func (c *Client) sendRequest(path string, params interface{}) (*resty.Response, error) {
url := c.apiHost + path
req := c.client.R().
SetHeader("Content-Type", "application/json").
@@ -51,7 +47,7 @@ func (c *Client) sendRequest(path string, params map[string]any) (*resty.Respons
return resp, nil
}
func (c *Client) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
func (c *Client) sendRequestWithResult(path string, params interface{}, result BaseResponse) error {
resp, err := c.sendRequest(path, params)
if err != nil {
return err