globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

allow pointer to struct in inline mode #145

Closed larrycinnabar closed 6 years ago

larrycinnabar commented 6 years ago

BSON encoder doesn't allow to use pointers to struct in inline mode.

There was an issue on the same topic on old repo: https://github.com/go-mgo/mgo/issues/346

Such structure:

type MStruct struct {
    M int `bson:"m,omitempty"`
}
type inlinePtrStruct struct {
    A int
    *MStruct `bson:",inline"`
}

is assumed to become {"a":0, "m":0} (without mstruct structure) - the same way as json encoder does it

without fix we get: "reflect: indirection through nil pointer to embedded struct"

larrycinnabar commented 6 years ago

close as open new one with the development branch