For following code, I'm expecting output of {"NewName" [{"NewName" []}]} but it's not updating child structs. How can we make sure it updates every struct in hierarchy.
package main
import (
"fmt"
)
type red struct {
Name string
Child []red
}
func (r *red) setName(nameString string){
r.Name = nameString
for _, child := range r.Child{
child.setName(nameString)
}
}
func main() {
obj := red{Name:"NameA",Child:[]red{red{Name: "NameB"}}}
fmt.Print(obj)
fmt.Print("\n")
obj.setName("NewName")
//Expectation {"NewName" [{"NewName" []}]}
fmt.Print(obj)
}