PR c/85696
[official-gcc.git] / libgo / go / fmt / example_test.go
blobaa3cd05e3ef22e4ace9e27e37fbd575d9c73e836
1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build ignore
7 package fmt_test
9 import (
10 "fmt"
13 // Animal has a Name and an Age to represent an animal.
14 type Animal struct {
15 Name string
16 Age uint
19 // String makes Animal satisfy the Stringer interface.
20 func (a Animal) String() string {
21 return fmt.Sprintf("%v (%d)", a.Name, a.Age)
24 func ExampleStringer() {
25 a := Animal{
26 Name: "Gopher",
27 Age: 2,
29 fmt.Println(a)
30 // Output: Gopher (2)