Defining types for functions
Go is a statically typed language. Although, we don’t have to spell out the type for each assignment – the types are there under the hood. It is effectively the compiler taking care of this for us. When we work with functions in Go, they are also implicitly assigned a type. While defining a type for a function in the way a compiler does it is a difficult task, we can use the concept of function aliases to add type safety to our code base.
When working with functions throughout the rest of this book, we will often use type aliases. This will help the compiler provide more readable error messages, and also makes our code more readable in general. Type aliases are, however, not just useful in the context of functions. They are a great feature of Go that is not too often used. It’s also a feature that you won’t easily find in other mainstream languages. So let’s take a dive into what type aliases are.
In essence, a type...