From 393cb66caeacfb7b6bc468ef6e923067253917f5 Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Fri, 30 Apr 2021 16:52:26 +0000 Subject: [PATCH] Add stringer --- stringer.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 stringer.go diff --git a/stringer.go b/stringer.go new file mode 100644 index 0000000..4abbb92 --- /dev/null +++ b/stringer.go @@ -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) + } +}