When you encode or decode into an object in Go, types that are not explicitly set will be set to their default values. Strings will default to empty string ("") and integers will default to 0, as an example. Normally, this is fine, unless 0 means something for your API or service that is consuming the user input or returning it.
In addition, if you use struct tags such as json omitempty, the 0 value will be ignored even if they're valid. Another example of this is Null, which returns from SQL. What value best represents Null for an Int? This recipe will explore some of the ways Go developers deal with this issue.
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/nulls.
- Navigate to this directory.
- Run the...