从JSON字符串中递归提取所有字符串值
(obj map[string]interface{}, values map[string]string, prefix string)
| 1054 | |
| 1055 | // 从JSON字符串中递归提取所有字符串值 |
| 1056 | func extractAllStringValues(obj map[string]interface{}, values map[string]string, prefix string) { |
| 1057 | for k, v := range obj { |
| 1058 | path := prefix |
| 1059 | if prefix != "" { |
| 1060 | path += "." + k |
| 1061 | } else { |
| 1062 | path = k |
| 1063 | } |
| 1064 | |
| 1065 | switch val := v.(type) { |
| 1066 | case string: |
| 1067 | values[path] = val |
| 1068 | case map[string]interface{}: |
| 1069 | extractAllStringValues(val, values, path) |
| 1070 | case []interface{}: |
| 1071 | for i, item := range val { |
| 1072 | if mapItem, ok := item.(map[string]interface{}); ok { |
| 1073 | extractAllStringValues(mapItem, values, fmt.Sprintf("%s[%d]", path, i)) |
| 1074 | } else if strItem, ok := item.(string); ok { |
| 1075 | values[fmt.Sprintf("%s[%d]", path, i)] = strItem |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | // 从流式响应中查找最有可能的完整内容 |
| 1083 | func findMostLikelyContent(lines []string, reqID string) string { |
no outgoing calls
no test coverage detected