Go is typically very flexible when used to convert data from one type to another. A type may inherit another type, as follows:
type A int
We can always cast back to the type we inherited, as follows:
var a A = 1
fmt.Println(int(a))
There are also convenience functions for converting between numbers using casting, between strings and other types using fmt.Sprint and strconv, and between interfaces and types using reflection. This recipe will explore some of these basic conversions, which will be used throughout this book.
How to do it...
The following steps cover how to write and run your application:
- From your Terminal/console application,createa new directory called~/projects/go-programming-cookbook/chapter3/dataconv.
- Navigate to this directory.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming...