This commit is contained in:
Fu Diwei 2025-03-22 17:51:27 +08:00
parent 9667f3309b
commit 516a958c66
2 changed files with 19 additions and 5 deletions

View File

@ -4,6 +4,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/url"
"reflect"
"strings" "strings"
"time" "time"
@ -35,21 +37,33 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
req.Method = method req.Method = method
req.URL = "https://cdn.api.baishan.com" + path req.URL = "https://cdn.api.baishan.com" + path
if strings.EqualFold(method, http.MethodGet) { if strings.EqualFold(method, http.MethodGet) {
qs := make(map[string]string) qs := url.Values{}
if params != nil { if params != nil {
temp := make(map[string]any) temp := make(map[string]any)
jsonb, _ := json.Marshal(params) jsonb, _ := json.Marshal(params)
json.Unmarshal(jsonb, &temp) json.Unmarshal(jsonb, &temp)
for k, v := range temp { for k, v := range temp {
if v != nil { if v != nil {
qs[k] = fmt.Sprintf("%v", v) rv := reflect.ValueOf(v)
switch rv.Kind() {
case reflect.Slice, reflect.Array:
for i := 0; i < rv.Len(); i++ {
qs.Add(fmt.Sprintf("%s[]", k), fmt.Sprintf("%v", rv.Index(i).Interface()))
}
case reflect.Map:
for _, rk := range rv.MapKeys() {
qs.Add(fmt.Sprintf("%s[%s]", k, rk.Interface()), fmt.Sprintf("%v", rv.MapIndex(rk).Interface()))
}
default:
qs.Set(k, fmt.Sprintf("%v", v))
}
} }
} }
} }
req = req. req = req.
SetQueryParams(qs). SetQueryParam("token", c.apiToken).
SetQueryParam("token", c.apiToken) SetQueryParamsFromValues(qs).SetDebug(true)
} else { } else {
req = req. req = req.
SetHeader("Content-Type", "application/json"). SetHeader("Content-Type", "application/json").

View File

@ -30,7 +30,7 @@ type CreateCertificateResponse struct {
} }
type GetDomainConfigRequest struct { type GetDomainConfigRequest struct {
Domains string `json:"domains"` Domains string `json:"domains"`
Config []string `json:"config"` Config []string `json:"config"`
} }