Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map[string]interface{}指针传到dataContext,在做 if 字段判断一直出现panic,求解 #48

Open
ljzhou1577 opened this issue May 6, 2022 · 3 comments

Comments

@ljzhou1577
Copy link

ljzhou1577 commented May 6, 2022

const ( data_rule = \
rule "data rule" "a test" salience 10
begin
println(up["status"])
if up["status"] == 1{
return true
}else{
return false
}
end `
)
func Test_check(t *testing.T) {
upDataMap := make(map[string]interface{})
busiz1 := []byte({"reference_id":2073666894,"status":1})
decoder1 := json.NewDecoder(bytes.NewReader(busiz1))
err := decoder1.Decode(&upDataMap)
if err != nil {
fmt.Printf("Unmarshal error, err: %+v", err)
return
}
dataContext := context.NewDataContext()
dataContext.Add("up", &upDataMap)
ruleBuilder := builder.NewRuleBuilder(dataContext)
err1 := ruleBuilder.BuildRuleFromString(data_rule)
if err1 != nil {
panic(err1)
}
eng := engine.NewGengine()
err2 := eng.Execute(ruleBuilder, true)
if err2 != nil {
panic(err2)
}
fmt.Printf("Finish")
}`

@ljzhou1577
Copy link
Author

if up["status"] == 1,这个地方一直出现panic,求解

@ljzhou1577 ljzhou1577 changed the title map[string]interface{}指针传到dataContext,在做 if 字段判断一直出现panic map[string]interface{}指针传到dataContext,在做 if 字段判断一直出现panic,求解 May 6, 2022
@daniel-007
Copy link

if up["status"] == 1,这个地方一直出现panic,求解

up["status"] 返回的是interface,你可以试试把upDataMap := make(map[string]interface{}) 改成 upDataMap := make(map[string]int)

@L-ance
Copy link

L-ance commented Sep 27, 2022

源码中的if判断只能用于number, bool, string 比较,判断数据类型时up["status"] 返回的是interface 不是number 类型
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants