The Error interface is a pretty small and simple interface:
type Error interface{
Error() string
}
This interface is elegant because it's simple to make anything in order to satisfy it. Unfortunately, this also creates confusion for packages that need to take certain actions depending on the error received.
There are a number of ways to create errors in Go; this recipe will explore the creation of basic errors, errors that have assigned values or types, and a custom error using a structure.
How to do it...
These steps cover the writing and running of your application:
- From your Terminal/console application,createa new directory called~/projects/go-programming-cookbook/chapter4/basicerrors and navigate to this directory.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter4/basicerrors...