
我遇到了这样一个问题:
我需要生成的 go struct 是:
type Base struct { ID bson.ObjectId `bson:"_id" json:"id,omitempty"` } 但是 thrift,我不知道怎么写?
struct Base { 1:? ID (go.tag = 'bson:"_id" json:"id,omitempty"') } bson.ObjectId 是 github.com/globalsign/mgo/bson 的内容
有使用过 threft 生成 go 的 struct 的吗? mongodb 的 objectId 如何处理那?
1 tairan2006 2020 年 4 月 2 日 via Android 大哥错别字太多了吧…用 string 就行 |
2 whalegao 2020 年 4 月 3 日 via iPhone 自己定义一个就行了 |
3 Zach369 OP @tairan2006 额 昨天写的有的急 ,,,,, 确实错别字有点多...... 不过我用 string 生成 string 的 id mgo 插入的时候报错 @whalegao 能说下具体怎么做吗? 自己定义, 就得实现这个生成 id 的方法啊 |
4 tairan2006 2020 年 4 月 3 日 @Zach369 string 和 ObjectId 可以相互转换的,你 insert 的时候不用指定 id,让 mongo 自动生成;读取的时候把 ObjectId 转给客户端。 |