Open winterspy opened 2 years ago
这个跟我碰到的问题类似,似乎是不支持转义字符,\n
被认为是字符串本身了
如果我规则内部写了 a = "abc\"def"
则在golang环境里打印会出来会是 abc\"def
而不是 abc"def
这个跟我碰到的问题类似,似乎是不支持转义字符,
\n
被认为是字符串本身了如果我规则内部写了
a = "abc\"def"
则在golang环境里打印会出来会是abc\"def
而不是abc"def
@matianjun1 现在的语法有点类似 Golang 的 raw string(但不完全一致),我提了一个 PR,把规则内字符串字面量的语法和 Go 里的双引号字符串 (interpreted string literals) 语法对齐了,也许可以解决你的问题
`package main
import ( "fmt" "github.com/bilibili/gengine/builder" "github.com/bilibili/gengine/context" "github.com/bilibili/gengine/engine" "github.com/sirupsen/logrus" "strings" "time" ) const rule1 =
rule "name test" "i can" salience 0 begin if FreeData == ""{ println("Error:data is null") }else{ rows = split(FreeData,"\n") println(rows[1]) } end
func main() { dataContext := context.NewDataContext() freeData :=total used free shared buff/cache available Mem: 131910844 41687584 24113760 4251248 66109500 84970700 Swap: 0 0 0
//这里可以成功切割出来 fmt.Println(strings.Split(freeData,"\n")[1]) //注入初始化的结构体 dataContext.Add("FreeData", freeData) dataContext.Add("split", strings.Split) dataContext.Add("println", fmt.Println)} `
第19行会报错: ERRO[0000] execute rule error: [rule: "name test" executed, error: line 8, column 3, code: println(rows[1]), reflect: slice index out of range
输出: Mem: 131910844 41687584 24113760 4251248 66109500 84970700 INFO[0000] rules num:1, load rules cost time:16206000
ERRO[0000] execute rule error: [rule: "name test" executed, error: line 8, column 3, code: println(rows[1]), reflect: slice index out of range goroutine 1 [running]: