Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Created November 8, 2016 00:45
Show Gist options
  • Save alexbosworth/be71869fd50ee23e76d6e4edefe9d2f1 to your computer and use it in GitHub Desktop.
Save alexbosworth/be71869fd50ee23e76d6e4edefe9d2f1 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type IPAddr [4]byte
func (ip IPAddr) String() string {
str := ""
for i := 0; i < len(ip); i++ {
str += fmt.Sprintf("%d.", ip[i])
}
return str[:len(str) - 1]
}
func main() {
hosts := map[string]IPAddr{
"loopback": {127, 0, 0, 1},
"googleDNS": {8, 8, 8, 8},
"simple": {1, 2, 3, 4},
}
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