yaegi
yaegi copied to clipboard
Not returning data struct when custom import populates the fields.
There are too many moving parts to produce a simple POC.
A custom import has a function that say returns data from a database:
func (h Handler) ReturnData(value interface) {
// Returns and populates the struct
}
This function is called from a script and the result is added to a slice.
result := make([]interface{}, 0)
...
t := *T
handler.ReturnData(t)
result = append(result, t)
...
return result
The script is executed as a "plugin". The data in the array is not returned. It appears as it's getting collected by the GC. You can access the data inside the script fine, you just can't return it.
If the script makes a copy of the data, it returns fine.
This works:
result := make([]interface{}, 0)
...
t := *T
handler.ReturnData(t)
cpy := *t
result = append(result, &cpy)
...
return result