Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
go-tour: add solution to the stringers exercise
Browse files Browse the repository at this point in the history
Fixes issue 187

LGTM=minux
R=adg, minux
CC=golang-codereviews
https://codereview.appspot.com/191520043
  • Loading branch information
campoy committed Jan 7, 2015
1 parent 380396f commit a30c657
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions solutions/stringers.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit a30c657

Please sign in to comment.