go-tour: add solution to the stringers exercise
Fixes #187
LGTM=minux
R=adg, minux
CC=golang-codereviews
https://golang.org/cl/191520043
diff --git a/solutions/stringers.go b/solutions/stringers.go
new file mode 100644
index 0000000..7462f4c
--- /dev/null
+++ b/solutions/stringers.go
@@ -0,0 +1,25 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ignore
+
+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() {
+ addrs := map[string]IPAddr{
+ "loopback": {127, 0, 0, 1},
+ "googleDNS": {8, 8, 8, 8},
+ }
+ for n, a := range addrs {
+ fmt.Printf("%v: %v\n", n, a)
+ }
+}