From 3d601145f4355f171cb9d5e1598691d4e545f4c8 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Mon, 13 Jan 2025 13:24:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E5=9C=A8=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E6=97=B6=E8=A1=A5=E9=BD=90=E7=BC=BA=E5=B0=91=E7=9A=84candle?= =?UTF-8?q?=E5=BA=8F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/extent.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/modules/extent.go b/modules/extent.go index 6bfb813..d58c1eb 100644 --- a/modules/extent.go +++ b/modules/extent.go @@ -260,10 +260,11 @@ func GetRangeCandleSortedSet(cr *core.Core, setName string, count int, from time parts := strings.Split(setName, "|") instId := parts[1] // 定义正则表达式,匹配 maX 或 candle 后面的内容直到第一个竖线 - re := regexp.MustCompile(`(?:maX|candle)([^\|]+)`) - // 使用正则表达式提取匹配的内容 - matches := re.FindStringSubmatch(setName) - err := InvokeCandle(cr, instId, matches[1], fromt, sti) + period, err := extractString(setName) + if err != nil { + return &cdl, err + } + err = InvokeCandle(cr, instId, period, fromt, sti) return &cdl, err } for _, str := range keyAry { @@ -286,6 +287,30 @@ func GetRangeCandleSortedSet(cr *core.Core, setName string, count int, from time return &cdl, nil } +func extractString(input string) (string, error) { + // 定位关键词 maX 或 candle + var prefix string + if strings.HasPrefix(input, "maX") { + prefix = "maX" + } else if strings.HasPrefix(input, "candle") { + prefix = "candle" + } else { + return "", fmt.Errorf("input does not start with 'maX' or 'candle'") + } + + // 去掉前缀部分 + remaining := strings.TrimPrefix(input, prefix) + + // 找到第一个竖线的位置 + pipeIndex := strings.Index(remaining, "|") + if pipeIndex == -1 { + return "", fmt.Errorf("no '|' found in the input") + } + + // 返回竖线之前的部分 + return remaining[:pipeIndex], nil +} + func GetExpiration(cr *core.Core, per string) (time.Duration, error) { if len(per) == 0 { erstr := fmt.Sprint("period没有设置")