refactor: 优化指标统计逻辑,减少锁的使用,提高性能

This commit is contained in:
2026-03-06 12:18:43 +08:00
parent 0f2d550a14
commit a6ed3f8f4c
6 changed files with 63 additions and 152 deletions

View File

@@ -38,14 +38,17 @@ func BuildFromProtocol(protocol, remainder string, originalQuery url.Values) (st
func mergeQuery(raw string, original url.Values) (string, error) {
parsed, err := url.Parse(raw)
if err != nil { return "", err }
if parsed.Scheme != "http" && parsed.Scheme != "https" {
return "", errors.New("不支持的协议")
}
if parsed.Host == "" {
return "", errors.New("目标地址无效")
}
// 合并 query
q := parsed.Query()
for k, vs := range original {
for _, v := range vs { q.Add(k, v) }
}
parsed.RawQuery = q.Encode()
if _, err := url.ParseRequestURI(parsed.String()); err != nil {
return "", err
}
return parsed.String(), nil
}