Closed
Description
I have a usecase where I want to distinguish 0 and nil so I'm trying to pass *int
to expr. Below is code I tried and it doesn't work as I had expected. How can get the value of pointer? I want to write expression like *num==1
or num.Value==1
but neither seems to work
package main
import (
"fmt"
"github.com/antonmedv/expr"
)
func main() {
num := 1
env := map[string]interface{}{
"num": &num,
}
p1, _ := expr.Compile(`num!=nil`, expr.Env(env))
o1, _ := expr.Run(p1, env)
fmt.Println(o1) // true
p2, _ := expr.Compile(`num==1`, expr.Env(env))
o2, _ := expr.Run(p2, env)
fmt.Println(o2) // false
p3, _ := expr.Compile(`num.Value==1`, expr.Env(env))
o3, _ := expr.Run(p3, env)
fmt.Println(o3) // nil
}