Add stringer

This commit is contained in:
Alex D. 2021-04-30 16:52:26 +00:00
parent e4b842666c
commit 393cb66cae
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
1 changed files with 19 additions and 0 deletions

19
stringer.go Normal file
View File

@ -0,0 +1,19 @@
package main
import "fmt"
type IPAddr [4]byte
func (ip IPAddr) String() string {
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
}
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)
}
}