Replies: 1 comment 1 reply
-
type Product struct {
Ticker string
}
func (p *Product) GetTicker() string {
return p.Ticker
}
type Env struct {
+ MyProduct *Product
- MyProduct Product
}
func main() {
code := `MyProduct.GetTicker()`
program, err := expr.Compile(code, expr.Env(Env{}))
if err != nil {
panic(err)
}
env := Env{
+ MyProduct: &Product{
- MyProduct: Product{
Ticker: "PETR4",
},
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(output)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I cannot seem to get the proper way to call a struct´s method from within an application. I assume its due to fact that parameters are passed in via an interface{} field but I cant find any information on how to get around it.
I get a panic like this one :
panic: type main.Product has no method GetTicker (1:11)
| MyProduct.GetTicker()
| ..........^
Can you please advise ? Here´s a sample code snippet
https://go.dev/play/p/_ziiXltEKue
Regards
Beta Was this translation helpful? Give feedback.
All reactions