Stringer
fmt.Stringer is a Go standard-library interface implemented by a type with a parameterless String method returning a textual representation.
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.
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.
Related concepts
- natural language interfacekind of · A natural language interface enables interaction with a system through human-language text or speech.
- currencyimplemented by · Currency is a system and unit of money used to express monetary value, facilitate exchange, and denominate financial amounts.
- monetary amountimplemented by · A monetary amount is a quantity of money represented by a numeric value together with a currency.
- interfacekind of · A software interface is a contract or boundary that specifies the operations, properties, or capabilities through which types or components interact, without requiring a particular implementation.
- string formattingused by · String formatting is the construction of text from values according to a specified format or template.
- fmtuses · fmt is a software library or package that provides formatted text generation and, in some implementations, formatted input and output operations.
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.


