Skip to content

Instantly share code, notes, and snippets.

@brianjester
Created October 8, 2017 22:25
Show Gist options
  • Save brianjester/b61a890340e00a3baeabe55577f1749a to your computer and use it in GitHub Desktop.
Save brianjester/b61a890340e00a3baeabe55577f1749a to your computer and use it in GitHub Desktop.
A Tour of Go - Methods and Interfaces - Exercise: Stringers (18/26)
package main
import "fmt"
type IPAddr [4]byte
func (ip IPAddr) String() string {
return fmt.Sprintf("%v.%v.%v.%v", ip[0],ip[1],ip[2],ip[3])
}
// TODO: Add a "String() string" method to IPAddr.
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