Created
January 29, 2019 20:48
-
-
Save ripiuk/762852fdc630cf3b44cf3b705f4cdbfb to your computer and use it in GitHub Desktop.
go tour exercise (methods/18)
This file contains hidden or 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" | |
"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