hashicorp / hashicorp/go-bexpr
Panic on using map[string]interface{}
- Dominant language
- Go
- Stars
- 123
- Forks
- 17
- Avg merge
- 7h 36m
- Merged PRs (30d)
- 3
Description
I am trying to use this library for evaluation of user provided expressions. Which means that there are no defined structs for objects. Instead it is a parsed JSON, (which simply outputs `map[string]interface{}`). However, this library seems unable to handle such use case? Or am I using it wrong way?
Example code:
```go
func main() {
userjson := `{"id": 123}`
filejson := `{"owner": 123}`
var User map[string]interface{}
var File map[string]interface{}
err := fastjson.Unmarshal([]byte(userjson), &User)
if err != nil {
panic(err)
}
err = fastjson.Unmarshal([]byte(filejson), &File)
if err != nil {
panic(err)
}
type Env map[string]interface{}
e := map[string]interface{}{
"file": File,
"user": User,
}
expr := "file.owner == user.id"
eval, err := bexpr.CreateEvaluatorForType(expr, nil, (*map[string]interface{})(nil))
if err != nil {
panic(err)
}
result, err := eval.Evaluate(e)
if err != nil {
panic(err)
}
fmt.Println(result)
}
```
Contributor guide
Assessment
This issue has not been assessed yet.