edmodo/thrift — pull request #9 by dvander (2014-04-30 05:53:38+00:00)
Title: Add support for nullable types in Go.

The Go library for Thrift, bizarrely, treats `0`, `false`, and `""` as unserializable values for primitive types. This means dynamic languages generally get nil/null/None where they should get something else. Normally that's okay since most of our numeric types are positive ids. For actual numeric data, it's broken.

Thrift's undocumented grammar supports "annotations" on various parser elements. It's not ideal, but it's enough of a hook into the parser to attempt an easy fix. For example:
```
struct Numbers {
1: optional double price (nullable="")
}
```

This patch uses the annotation list on struct fields, and when it sees a "nullable" annotation, creates the field as a pointer type, and uses "nil" as the unserializable value instead. The "nullable" annotation will do nothing on non-basic types, and won't work with default values. It will work with "required" fields but there's not really a reason to do that.

Unfortunately, Go's type system is pretty puny, so it doesn't have either sugared nullable types or ways to construct the sugar ourselves (such as via tagged unions). We'll probably need to build helpers like this to stay sane:
```
func Int64Ptr(n int64) *int64 { return &n }
```

(Most of the code motion is just unindenting - there's two separate commits to make that clearer.)