Go:接口作为返回值

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?

Pass a pointer to the sice as an argument:

func LookUp(collection string, ids []string, result interface{}) error {
     // Is in cache?
     // if not get them from database
     return db.C(collection).Find(bson.M{"_id": bson.M{"$in": ids}}).All(result)
}

Call it like this:

var dogs []*Doc
err := Lookup("dog", dogIds, &dogs)
if err != nil 
   // handle error
}

Generally, with MongoDB, you would use bson struct to quickly add or retrieve objects (which are embedded documents).

You can see this example

// Find the actors in the movie
var m Movie
db.C("movies").Find(bson.M{"name": "Fantastic Mr. Fox"}).One(&m)

That means one Lookup function per struct indeed.