From a0ab180b2c3ce0241a2c546664fb1a8e5ba8048e Mon Sep 17 00:00:00 2001 From: WangLiZhao <1838393649@qq.com> Date: Tue, 30 Jun 2026 15:58:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(util):=20=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=98=A0=E5=B0=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/util/mapping.go | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/common/util/mapping.go b/common/util/mapping.go index d91d22a..11be623 100644 --- a/common/util/mapping.go +++ b/common/util/mapping.go @@ -1,6 +1,7 @@ package util import ( + "encoding/json" "fmt" "strings" @@ -114,33 +115,18 @@ func buildAttachment(tmpl map[string]any, url string) map[string]any { return nil } - body := gconv.Map(tmpl["body"]) - fillEmptyInPlace(body, url) + // 深拷贝模板 + b, _ := json.Marshal(tmpl) + str := string(b) + str = strings.ReplaceAll(str, `"{{url}}"`, `"`+url+`"`) - result := map[string]any{ - "type": typ, - typ: body, - } - if role, ok := tmpl["role"].(string); ok && role != "" { - result["role"] = role - } + var result map[string]any + _ = json.Unmarshal([]byte(str), &result) + delete(result, "type") + result["type"] = typ return result } -// fillEmptyInPlace 递归填充空字符串 -func fillEmptyInPlace(m map[string]any, value string) { - for k, v := range m { - switch vv := v.(type) { - case string: - if vv == "" { - m[k] = value - } - case map[string]any: - fillEmptyInPlace(vv, value) - } - } -} - // ======================== 系统提示词合并 ======================== // MergeSystemPrompt 将系统提示词和技能内容拼接到 system role 的 content 中