samuel / go-thrift

A native Thrift package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support 'union' structs

ximyu opened this issue · comments

Currently when I try to parse a Thrift file using union, I'll get the following error messages:

2015/08/17 10:37:41 Could not parse .thrift file: <reader>:164:1 (3915): rule SyntaxError: parser: syntax error

By some search, below is a real world example Thrift file using union quite a lot. Would be nice to also add this to test files.
https://github.com/apache/aurora/blob/master/api/src/main/thrift/org/apache/aurora/gen/api.thrift

Parsing is straightforward.. the trick will be how to represent it in Go (e.g. as an interface{} or synthesize a struct with multiple fields of concrete types or ...)

I think the Apache Thrift one will represent union as a Golang struct.

Thrift:

union Query {
  1: string id
  2: string name
}

Generated Go:

type Query struct {
    Id       string   `thrift:"id,1" json:"id"`
    Name string `thrift:"name,2" json:"name"`
}

Ahh, good to know. Probably best to do the same.