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

Facing Issue with Govaluate Custom functions #192

Open
Yash1256 opened this issue Dec 18, 2023 · 1 comment
Open

Facing Issue with Govaluate Custom functions #192

Yash1256 opened this issue Dec 18, 2023 · 1 comment

Comments

@Yash1256
Copy link

Hi, I have been using govaluate in my code since a long time.. but I faced this issue very recently..
The issue is described as
I wrote my custom function names as len which definition is as below..

"len": func(args ...interface{}) (interface{}, error) {
	fmt.Printf("Received args: %#v\n", args)
	return len(args), nil
}

And what am I doing is passing empty array to this function and writing an expression which says => len(array) != 0
The logs I recieved

Evaluating expression:  len(array) != 0  with params:  map[array:[]]

and it's giving the result as true that length is not equals to 0.. while the function logs are

Received args: []interface{}{}

But the same thing when I tried with the len(args) as a string.. by using strconv.Itoa(len(args)) and did len(array) != '0' it worked..
May someone please help me out here.

@zhangjianxiongZJX
Copy link

len(args) is the length of argments of function,you pass an argment to funtion, so length of argment is one. the argment's value is []interface{}{}, array is it's real type. if you want to get len(array). you must type assert at first. just like this:
arr := args[0].([]interface{}), then len(arr)

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

2 participants