Как определить тип m go objectId с помощью Apache Thrift? - PullRequest
0 голосов
/ 02 апреля 2020

Я использую Apache Thrift для определения структуры.

struct Base {
    1:string  ID (go.tag = 'bson:"_id" json:"id,omitempty"')
}

После выполнения команды "thrift --gen go base.thrift"
Я хочу, чтобы она выглядела как this.

type Base struct {
    ID bson.ObjectId `bson:"_id" json:"id,omitempty"`
}

bson.ObjectId исходит от github.com/globalsign/mgo/bson

// NewObjectId returns a new unique ObjectId.
func NewObjectId() ObjectId {
    var b [12]byte
    // Timestamp, 4 bytes, big endian
    binary.BigEndian.PutUint32(b[:], uint32(time.Now().Unix()))
    // Machine, first 3 bytes of md5(hostname)
    b[4] = machineId[0]
    b[5] = machineId[1]
    b[6] = machineId[2]
    // Pid, 2 bytes, specs don't specify endianness, but we use big endian.
    b[7] = byte(processId >> 8)
    b[8] = byte(processId)
    // Increment, 3 bytes, big endian
    i := atomic.AddUint32(&objectIdCounter, 1)
    b[9] = byte(i >> 16)
    b[10] = byte(i >> 8)
    b[11] = byte(i)
    return ObjectId(b[:])
}
...