This is a created article in which the information may have evolved or changed.
Errors Bag
Check out the Golang errors package and you'll find its source code:
func New(text string) error {return &errorString{text}}// errorString is a trivial implementation of error.type errorString struct {s string}func (e *errorString) Error() string {return e.s}
A pointer to the ErrorString type that implements the error interface is returned. Then why not return the value type of errorstring??
You may say: Because only ' *errorstring ' has the ' Error ' method ...
Wrong, and the wrong mistake.
Positive solution:
We are calling errors. New ("") to return an error, you can compare the pointer to compare the error equality, actually control the same error we only create an Error object. Otherwise the object is copied and the comparison is false.
And the pointer will be compared to nil, if the string "" Although the error content is empty, but there are errors.