method pass pointer of struct
examples/method-pass-pointer/method_pass_pointer.go
package main import "fmt" type aPerson struct { name string } func (p *aPerson) changeName(newName string) { fmt.Printf("Old name: %v\n", p.name) p.name = newName fmt.Printf("New name: %v\n", p.name) } func main() { joe := aPerson{name: "Joe"} fmt.Println(joe) joe.changeName("Jane") fmt.Println(joe) }
{Joe} Old name: Joe New name: Jane {Jane}