Golang control annotations in flattened generated code

I have a thrift message that I would like to be able to serialize to and from json, but I don't want the generated json keys to match what is in the generated go code.

Is there a way to control which annotations are tied to the structure in go code that generates lean?

+4
source share
1 answer

Eliminate my previous answer - it is undocumented, but it's possible, I found it by reading the compiler code. Bah.

But in any case, in economical master (1.0-dev), here's how to do it - using annotation go.tag.

This thrift code:

struct foo {
  1: string bar (go.tag = "json:\"baz\" yo:\"dawg\""),
  2: string bang
}

Generates the following Go code:

type Foo struct {
        Bar  string `thrift:"bar,1" json:"baz" yo:"dawg"`
        Bang string `thrift:"bang,2" json:"bang"`
}
+3
source

All Articles