Commit 58f84fdf authored by Blain Smith's avatar Blain Smith Committed by Ian Lance Taylor

fmt: add Stringer example

Change-Id: I901f995f8aedee47c48252745816e53192d4b7e4
Reviewed-on: https://go-review.googlesource.com/49090Reviewed-by: default avatarSam Whited <sam@samwhited.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Sam Whited <sam@samwhited.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent e82e1204
// Copyright 2017 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.
package fmt_test
import (
"fmt"
)
// Animal has a Name and an Age to represent an animal.
type Animal struct {
Name string
Age uint
}
// String makes Animal satisfy the Stringer interface.
func (a Animal) String() string {
return fmt.Sprintf("%v (%d)", a.Name, a.Age)
}
func ExampleStringer() {
a := Animal{
Name: "Gopher",
Age: 2,
}
fmt.Println(a)
// Output: Gopher (2)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment