在 thrift 生成的代码中控制 golang 注释

Control golang annotations in thrift generated code

我收到一条来自 thrift 的消息,我希望能够序列化进出 json,但我不希望生成的 json 键与生成的代码。

有没有办法控制 thrift 生成的 go 代码中的结构附加了哪些注释?

记下我之前的答案 - 它没有记录,但它是可能的,我通过阅读编译器代码找到了它。

但无论如何,在 thrift 的 master (1.0-dev) 中,这是如何完成的 - 使用 go.tag 注释。

这段thrift代码:

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

生成以下 Go 代码:

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