Skip to content

Instantly share code, notes, and snippets.

@NikoTung
Created May 31, 2018 05:28
Show Gist options
  • Save NikoTung/c8d78ae922bee230d49d93f28c7b6338 to your computer and use it in GitHub Desktop.
Save NikoTung/c8d78ae922bee230d49d93f28c7b6338 to your computer and use it in GitHub Desktop.
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)
}
}
@NikoTung
Copy link
Author

NikoTung commented May 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment