Skip to content

Commit 516a958

Browse files
committed
1 parent 9667f33 commit 516a958

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

internal/pkg/vendors/baishan-sdk/client.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"net/url"
8+
"reflect"
79
"strings"
810
"time"
911

@@ -35,21 +37,33 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
3537
req.Method = method
3638
req.URL = "https://cdn.api.baishan.com" + path
3739
if strings.EqualFold(method, http.MethodGet) {
38-
qs := make(map[string]string)
40+
qs := url.Values{}
3941
if params != nil {
4042
temp := make(map[string]any)
4143
jsonb, _ := json.Marshal(params)
4244
json.Unmarshal(jsonb, &temp)
4345
for k, v := range temp {
4446
if v != nil {
45-
qs[k] = fmt.Sprintf("%v", v)
47+
rv := reflect.ValueOf(v)
48+
switch rv.Kind() {
49+
case reflect.Slice, reflect.Array:
50+
for i := 0; i < rv.Len(); i++ {
51+
qs.Add(fmt.Sprintf("%s[]", k), fmt.Sprintf("%v", rv.Index(i).Interface()))
52+
}
53+
case reflect.Map:
54+
for _, rk := range rv.MapKeys() {
55+
qs.Add(fmt.Sprintf("%s[%s]", k, rk.Interface()), fmt.Sprintf("%v", rv.MapIndex(rk).Interface()))
56+
}
57+
default:
58+
qs.Set(k, fmt.Sprintf("%v", v))
59+
}
4660
}
4761
}
4862
}
4963

5064
req = req.
51-
SetQueryParams(qs).
52-
SetQueryParam("token", c.apiToken)
65+
SetQueryParam("token", c.apiToken).
66+
SetQueryParamsFromValues(qs).SetDebug(true)
5367
} else {
5468
req = req.
5569
SetHeader("Content-Type", "application/json").

internal/pkg/vendors/baishan-sdk/models.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type CreateCertificateResponse struct {
3030
}
3131

3232
type GetDomainConfigRequest struct {
33-
Domains string `json:"domains"`
33+
Domains string `json:"domains"`
3434
Config []string `json:"config"`
3535
}
3636

0 commit comments

Comments
 (0)