Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
tour_of_goの例題
package main
import (
"fmt"
"strings"
)
type IPAddr [4]byte
func (i IPAddr) String() string {
var values []string
for _, m := range i {
values = append(values, fmt.Sprintf("%v", m))
}
return strings.Join(values, ".")
}
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment