Complete the code to declare the error interface method.
type error interface {
[1]() string
}The error interface requires a method named Error that returns a string.
Complete the code to implement the error interface for MyError type.
type MyError struct {
msg string
}
func (e MyError) [1]() string {
return e.msg
}The method to implement the error interface must be named Error and return a string.
Fix the error in the function signature to correctly implement the error interface.
func (e *MyError) [1]() string { return e.msg }
The method name must be exactly Error without parentheses in the declaration.
Fill both blanks to create a function that returns an error interface value.
func NewError(msg string) [1] { return &[2]{msg} }
The function returns the error interface type and returns a pointer to MyError struct initialized with the message.
Fill all three blanks to check if an error is nil and print its message.
var err [1] = NewError("fail") if err [2] nil { fmt.Println(err.[3]()) }
Declare err as type error, check if it is not nil, then call its Error() method to print the message.