Neni mi jasne jaktoze se v nasledujicim kodu pouzije metoda i kdyz neni explicitne volana.
package main
import (
"fmt"
"strconv"
"strings"
)
type IPAddr [4]byte
func (ip IPAddr) String() string {
s := make([]string, len(ip))
for i, val := range ip {
s[i] = strconv.Itoa(int(val))
}
return strings.Join(s, ".")
}
func main() {
hosts := map[string]IPAddr{
"loopback": {127, 0, 0, 1},
"googleDNS": {8, 8, 8, 8},
}
for name, ip := range hosts {
fmt.Printf("%v: %v\n", name, ip)
}
}