I have some arrays of different struct, and I need to change them by the same function func foo(arr interface{})
.
And I use the function in this way foo(&arrayToChange)
Then I find that, I cannot change the array by pointer a simple example for you.
package main
import (
"fmt"
)
func A(out interface{}) {
arr := make([]interface{}, 0)
arr = append(arr, "foo", 2.2)
out = &arr
B(out)
}
func B(out interface{}) {
arr := make([]interface{}, 0)
arr = append(arr, "bar", "foo", "anything")
out = &arr
}
func main() {
arr := make([]interface{}, 0)
arr = append(arr, 1, 2, 3)
fmt.Printf("%T
", &arr)
A(&arr)
fmt.Println(arr)
}