furusiyya
furusiyya

Reputation: 79

How to implement both fmt.Stringer and error interface on a type?

As with fmt.Stringer, the fmt package looks for the error interface when printing values. In case if a type satisfies both interfaces, fmt only on look for error not Stringer. Why? How I could implement both Stringer and error on a type?

Upvotes: 2

Views: 1315

Answers (1)

user7482686
user7482686

Reputation: 21

Not really a universal solution, but in certain situations one can use pointer vs non-pointer receivers to do the trick: https://play.golang.org/p/DY4Cq4efsT

Upvotes: 2

Related Questions