New to Go, so please bear with me.
I've been looking at the "Tour of Go" pages, and stumbled into something puzzling about Stringers. Consider the exercise at https://tour.golang.org/methods/18
My initial answer was implementing
func (this *IPAddr) String() string {
return fmt.Sprintf("%d.%d.%d.%d", this[0], this[1], this[2], this[3])
}
however, this is not used f main prints just fmt.Printf("%v: %v
", name, ip)
. If I change the print to fmt.Printf("%v: %v
", name, ip.String())
, then it is used whether the receiver type is *IPAddr
or IPAddr
).
why is this happening?