From 7d8ff9a26c09b20c0d3048fc5f321a093fae6e58 Mon Sep 17 00:00:00 2001 From: zu1k Date: Sat, 18 Jul 2020 14:26:22 +0800 Subject: [PATCH] fix muti replace --- internal/app/cdn.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/app/cdn.go b/internal/app/cdn.go index 0f22892..28c83d6 100644 --- a/internal/app/cdn.go +++ b/internal/app/cdn.go @@ -47,12 +47,18 @@ func find(cname string) string { } func ReplaceCDNInString(str string) (result string) { + done := make(map[string]bool) + cnames := domainRe.FindAllString(str, -1) result = str for _, cname := range cnames { name := find(cname) if name != "未找到" && name != "无法解析" { + if _, found := done[cname]; found { + continue + } result = strings.ReplaceAll(result, cname, fmt.Sprintf("%s [%s]", cname, name)) + done[cname] = true } } return