- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15
 
Open
Labels
enhancementNew feature or requestNew feature or request
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:
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)
}Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request