I have several structs which I fill with data from MongoDB.
type Dog struct {
Id string
Age int
}
type Invoice struct {
Id int
Amount float
}
I was trying to make a function like this:
func LookUp(collection string, ids []string) []interface{} {
// Is in cache?
// if not get them from database
}
This way i could do something like:
func GoodDogs() []string{
// Give the ids of good dogs
}
dogsIds := GoodDogs()
dogs := LookUp("Dogs", namesToRetrieve)
I know i could write the same function over and over for each struct, setting the correct return type and id type (notice some are int, some strings) but... seems too anti DRY.
Interfaces seem to work the other way, for the inputs. Is there a way to do what I'm trying? Or is this is just a wrong design pattern?