优化HTTP请求处理和模块租户检查逻辑:支持GET请求参数转换,简化日志消费者配置,改进RPC调用方式
This commit is contained in:
13
http/http.go
13
http/http.go
@@ -83,7 +83,18 @@ func doRequest(ctx context.Context, method string, url string, headers map[strin
|
||||
// 修复:避免data...展开导致的双重包装问题
|
||||
// 当只有一个元素时,直接传递该元素,避免被包装成数组
|
||||
var response *gclient.Response
|
||||
if len(data) == 1 {
|
||||
// 对于GET请求,将参数转换为map
|
||||
if method == http.MethodGet && len(data) > 0 && len(data)%2 == 0 {
|
||||
// 构建query参数map
|
||||
queryParams := make(map[string]string)
|
||||
for i := 0; i < len(data); i += 2 {
|
||||
if key, ok := data[i].(string); ok && i+1 < len(data) {
|
||||
queryParams[key] = gconv.String(data[i+1])
|
||||
}
|
||||
}
|
||||
g.Log().Infof(ctx, "[HTTP] GET请求构建的query参数: %+v", queryParams)
|
||||
response, err = client.DoRequest(ctx, method, url, queryParams)
|
||||
} else if len(data) == 1 {
|
||||
response, err = client.DoRequest(ctx, method, url, data[0])
|
||||
} else {
|
||||
response, err = client.DoRequest(ctx, method, url, data...)
|
||||
|
||||
Reference in New Issue
Block a user