The golang comes with a fair amount of functions end up returning errors like values.
The golang errors function looking like this:

You can use the errors package and that implements functions to manipulate errors.
The official golang example:

You can see how it created the new custom errors using the New function:

The fmt package formats an error value by calling its Errorf() string method, see the example:

You can add more information about the error using struct types and fields.
The error type is an interface type and can be used in this way.

And an error variable represents any value that can describe itself as a string, see the example:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.