Skip to content

Instantly share code, notes, and snippets.

@ripiuk
Created January 29, 2019 20:48
Show Gist options
  • Save ripiuk/762852fdc630cf3b44cf3b705f4cdbfb to your computer and use it in GitHub Desktop.
Save ripiuk/762852fdc630cf3b44cf3b705f4cdbfb to your computer and use it in GitHub Desktop.
go tour exercise (methods/18)
package main
import (
"fmt"
"strconv"
"strings"
)
type IPAddr [4]byte
func (ip IPAddr) String() string {
var s []string
for _, i := range ip {
s = append(s, strconv.Itoa(int(i)))
}
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment