I would like to have some kind of a "hook" that runs whenever I get a specific type of object from the database. I thought the Unmarshaler
interface is perfect for that, but... How can I implement that interface without manually unmarshalling every single field myself?
I thought of doing something like this:
func (t *T) UnmarshalBSON(b []byte) error {
// Simply unmarshal `b` into `t` like it would otherwise
bson.Unmarshal(b, t) // Obviously this won't work, it'll be an infinite loop
// Do something here
return nil
}
How could I achieve this without manually unmarshalling the fields using the reflect pkg?