Is there a eval() like method on golang?
Evaluate/Execute JavaScript code/expressions:
var x = 10;
var y = 20;
var a = eval(\"x * y\
Its perfectly possible. At least for expressions, which seems to be what you want:
Have a look at:
https://golang.org/src/go/types/eval.go
https://golang.org/src/go/constant/value.go
https://golang.org/pkg/go/types/#Scope
You'd need to create your own Package
and Scope
objects and Insert
constants to the package's scope. Constants are created using types.NewConst
by providing appropriate type information.