Implementing error interface

Implement the error interface by defining a type with an Error() string method to return a custom error message.

Implement the error interface by defining a type with a single Error() string method.

type MyError struct {
    message string
}

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

The error interface is satisfied automatically when any type defines this method, allowing it to be returned from functions expecting an error.