samuel/go-thrift — pull request #10 by dmcgowan (2013-05-21 05:34:48+00:00)
Title: Fix for ErrUnknownType within included files

When a type is a defined and used in an include the generator will throw an ErrUnknownType since it will be looking for the type as the name defined in the include while the Thrift object has the types keyed off the include name + the name of the type.

The error would show up with two files with a pattern such as...

base.thrift
~~~~
typedef string UUID

struct Context {
1: required UUID id,
2: optional string data
}
~~~~

someservice.thrift
~~~~
include "base.thrift"
~~~~

The error being {ErrUnknownType UUID} since the struct is stored as base.UUID.

The solution I coded up stores the include name along with the type and first looks for the include name plus the type name before looking for the type name when the include name exists. I think a better solution would be to bring the behavior of the generator in line with other thrift generators by using the namespace of the includes to form a proper import statement, but that is another discussion.