Create custom types for errors that need extra data:
type ValidationError struct {
Field string
Msg string
}
func (e ValidationError) Error() string {
return fmt.Sprintf("%s: %s", e.Field, e.Msg)
}
Any type with an Error() method satisfies the error interface. Custom types let you include structured information.