Documentation
¶
Overview ¶
Package flatbson provides a function for recursively flattening a Go struct using its BSON tags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flatten ¶
Flatten returns a map with keys and values corresponding to the field name and values of struct v and its nested structs according to its BSON tags. It iterates over each field recursively and sets fields that are not nil.
The BSON struct tags behave in line with the bsoncodec specification. See: https://godoc.org/go.mongodb.org/mongo-driver/bson/bsoncodec#StructTags for definitions. The supported tags are name, skip, omitempty, and inline.
Flatten does not flatten structs with unexported fields, e.g. time.Time. It returns an error if v is not a struct or a pointer to a struct, or if the tags produce duplicate keys.
type A struct { B *X `bson:"b,omitempty"` C X `bson:"c"` } type X struct { Y string `bson:"y"` } Flatten(A{nil, X{"hello"}}) // Returns: // map[string]interface{}{"c.y": "hello"}
Types ¶
This section is empty.