Search⌘ K
AI Features

Challenge: Implement the Stringer Interface

Explore implementing the Stringer interface for an Item type in Go. Learn how to define a method to customize how Item variables print, displaying either the author's name or a default value. This lesson helps you understand interfaces and their practical use in Go's standard library.

Problem statement

We have learned that the fmt package from the standard library defines the Stringer interface as follows:

type Stringer interface {
String() string
}

For this challenge, you need to complete the code below such that the type Item implements the Stringer ...