pomack / thrift4go

Apache Thrift for the Go Language
129 stars 23 forks source link

how to use thrift query mongo '_id' field? #64

Open zhymin77 opened 11 years ago

zhymin77 commented 11 years ago

how to struct a field, when i extract mongo '_id' field's value? I use mgo driver. I can define a Struct like that: type Test struct { ID string "_id" } extract '_id' value to ID field successfully .

tks.

pomack commented 11 years ago

I believe mgo uses the bson tag as such:

type Test struct {
  ID string `bson:"_id"`
}
zhymin77 commented 11 years ago

yes, :)

How to define struct like this use thrift4go?

pomack commented 11 years ago

Thrift doesn't support this in the spec file and therefore there's no way to auto-generate with tags this way. You can create your own structs and then write conversion functions between the auto-generated struct and your own struct.

zhymin77 commented 11 years ago

tks :+1:

zhymin77 commented 11 years ago

I use a helper to convert query map data to thrift obj.