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

@@ -34,7 +34,7 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
return c
}
func (c *Client) sendRequest(method string, path string, params map[string]any) (*resty.Response, error) {
func (c *Client) sendRequest(method string, path string, params interface{}) (*resty.Response, error) {
req := c.client.R()
req.Method = method
req.URL = c.apiHost + path
@@ -42,11 +42,17 @@ func (c *Client) sendRequest(method string, path string, params map[string]any)
SetHeader("api-key", c.apiKey).
SetHeader("api-secret", c.apiSecret)
if strings.EqualFold(method, http.MethodGet) {
data := make(map[string]string)
for k, v := range params {
data[k] = fmt.Sprintf("%v", v)
qs := make(map[string]string)
if params != nil {
temp := make(map[string]any)
jsonData, _ := json.Marshal(params)
json.Unmarshal(jsonData, &temp)
for k, v := range temp {
qs[k] = fmt.Sprintf("%v", v)
}
}
req = req.SetQueryParams(data)
req = req.SetQueryParams(qs)
} else {
req = req.
SetHeader("Content-Type", "application/json").
@@ -63,7 +69,7 @@ func (c *Client) sendRequest(method string, path string, params map[string]any)
return resp, nil
}
func (c *Client) sendRequestWithResult(method string, path string, params map[string]any, result BaseResponse) error {
func (c *Client) sendRequestWithResult(method string, path string, params interface{}, result BaseResponse) error {
resp, err := c.sendRequest(method, path, params)
if err != nil {
return err