Created
May 31, 2018 05:28
-
-
Save nikotung/c8d78ae922bee230d49d93f28c7b6338 to your computer and use it in GitHub Desktop.
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" | |
"strings" | |
) | |
type IPAddr [4]byte | |
func (p IPAddr) String() string { | |
var v []string | |
for i := range p { | |
byte := p[i] | |
s := fmt.Sprintf("%v", byte) | |
v = append(v, s) | |
} | |
return fmt.Sprintf("%v", strings.Join(v[:],".")) | |
} | |
// 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
https://tour.go-zh.org/methods/18