liveBook · Manning

Stringer

fmt.Stringer is a Go standard-library interface implemented by a type with a parameterless String method returning a textual representation.

How 3 Manning books explain it

Learn Go with Pocket-Sized Projects

The Stringer interface is the fmt convention satisfied by a type with a parameterless String method returning a string.

How it is used
Formats domain values through Go’s fmt printing and formatting functions.
How deep it goes
Defines the one-method contract and demonstrates implementations, formatting behavior, composition, and receiver choices.
Examples
Demonstrates hint, feedback, Currency, Decimal, and Amount values with custom textual representations.
What you can do after
Apply it via fmt.Print* and formatting verbs to produce readable representations for custom Go types.

Read how Learn Go with Pocket-Sized Projects explains Stringer →

Go in Action, Second Edition

Stringer is a Go interface conventionally satisfied by a type that provides a String method for custom textual formatting.

How it is used
Uses Stringer to control how domain values appear when formatted by fmt.Printf and similar functions.
How deep it goes
Explains the method contract, naming convention, structural satisfaction, and compile-time verification.
Examples
Formats measurement units using common abbreviations and an underlying-string fallback.
What you can do after
Apply it by implementing String() so Go formatting functions display domain values meaningfully.

Read how Go in Action, Second Edition explains Stringer →

Go in Practice, Second Edition

fmt.Stringer is a Go standard-library interface implemented by types that provide a parameterless String method returning a string.

How it is used
Uses Stringer to recognize values that provide their own string representation and to demonstrate interface conformance checks.
How deep it goes
Defines the method shape and demonstrates assertion and reflection checks, without developing broader formatting behavior.
Examples
Demonstrates Stringer with a Name type and compares it against io.Writer using runnable assertion and reflection examples.
What you can do after
Apply type assertions or the reflect package to determine whether values or types implement Stringer.

Read how Go in Practice, Second Edition explains Stringer →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.