globalsign / mgo

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

Add switch for ignoring `omitempty` #130

Closed kassiansun closed 6 years ago

kassiansun commented 6 years ago

Currently we have bson.SetJSONTagFallback to fallback to json tag when no bson tag available, which is pretty useful when using protobuf with mgo, leave generated *.pb.go untouched and get a consistent field name between json & bson.

With the default omitempty tag generated by protobuf, updated struct fields with empty values will not be encoded, leave the database untouched. Adding a switch for ignoring omitempty will gain another benefit that we can keep protobuf performant and make updating operations easier.