I have a function like the following for querying a mongo database:
func findEntry(db, table string, entry *User, finder *bson.M) (err error) {
c := mongoSession.DB(db).C(table)
return c.Find(finder).One(entry)
}
I'd like to reuse the function for structs other than "User", by passing in a pointer to any instantiated struct object - just not quite sure of the proper semantics to do this. I think that I should be able to do this by making the 'entry' parameter an interface{} and then I'd need to use reflection to 'cast' it back to the original struct so the One() function call could properly fill in the struct on the call? Is there a 'better' way to accomplish this (please no flaming about lack of generics, I'm just looking for a practical solution using best practices).