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

Can we make the fromJSON function support string pointer? #739

Open
Cassius0924 opened this issue Dec 13, 2024 · 3 comments
Open

Can we make the fromJSON function support string pointer? #739

Cassius0924 opened this issue Dec 13, 2024 · 3 comments
Labels

Comments

@Cassius0924
Copy link

The current fromJSON function only supports parameters of type string. If I pass a parameter of type *string, it throws an error.

@antonmedv antonmedv added the bug label Dec 13, 2024
@antonmedv
Copy link
Member

Looks like a deref is missing. Could you please share the whole example?

@Cassius0924
Copy link
Author

Cassius0924 commented Dec 13, 2024

Looks like a deref is missing. Could you please share the whole example?看起来缺少 deref。您能分享整个示例吗?

sure!

package main

import (
	"fmt"

	"github.com/expr-lang/expr"
)

func main() {
	jsonString := `{"Num": 1}`
	env := map[string]any{
		"aJSONString": &jsonString,
	}

	code := "fromJSON(aJSONString)"
	result, err := expr.Eval(code, env)
	if err != nil {
		panic(err)
	}
	fmt.Println(result)
}
panic: interface conversion: interface {} is *string, not string (1:1)
	 | fromJSON(aJSONString)
	 | ^

goroutine 1 [running]:

@Cassius0924
Copy link
Author

and split

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

No branches or pull requests

2 participants