Skip to content

Instantly share code, notes, and snippets.

@ta1kt0me
Created January 22, 2017 04:11
Show Gist options
  • Select an option

  • Save ta1kt0me/299a48b68eb569f2e5db2ab247ff541c to your computer and use it in GitHub Desktop.

Select an option

Save ta1kt0me/299a48b68eb569f2e5db2ab247ff541c to your computer and use it in GitHub Desktop.
Exercise: Stringers
package main
import (
"fmt"
"strconv"
)
type IPAddr [4]byte
func (ip IPAddr) String() string {
var str string
for i, v := range ip {
if i != 0 {
str += "."
}
str += strconv.Itoa(int(v))
}
return fmt.Sprintf("%v", str)
}
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