How to Implement the error Interface for Custom Errors

Implement the error interface in Go by adding an Error() method that returns a string to your custom type.

Implement the error interface by defining a method named Error() that returns a string on your custom type. This single method satisfies the interface, allowing your type to be used wherever an error is expected.

type MyError struct {
	msg string
}

func (e MyError) Error() string {
	return e.msg
}