Source file tour/solutions/stringers.go

     1  //go:build OMIT
     2  
     3  // Copyright 2015 The Go Authors.  All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import "fmt"
    10  
    11  type IPAddr [4]byte
    12  
    13  func (ip IPAddr) String() string {
    14  	return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
    15  }
    16  
    17  func main() {
    18  	addrs := map[string]IPAddr{
    19  		"loopback":  {127, 0, 0, 1},
    20  		"googleDNS": {8, 8, 8, 8},
    21  	}
    22  	for n, a := range addrs {
    23  		fmt.Printf("%v: %v\n", n, a)
    24  	}
    25  }
    26  

View as plain text