Created
November 8, 2016 00:45
-
-
Save alexbosworth/be71869fd50ee23e76d6e4edefe9d2f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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