title: Go and MongoDB: generic DAO implementation issue
body: <p>In the current project we use Go and MongoDB via mgo driver.
  For every entity we have to implement DAO for CRUD operations, and it's basically copy-paste, e.g.</p>
  
  <pre><code>func (thisDao ClusterDao) FindAll() ([]*entity.User, error) {
      session, collection := thisDao.getCollection()
      defer session.Close()
      result := []*entity.User{} //create a new empty slice to return 
      q := bson.M{}
      err := collection.Find(q).All(&amp;result)
      return result, err
  }
  </code></pre>
  
  <p>For every other entity it's all the same but the result type.</p>
  
  <p>Since Go has no generics, how could we avoid code duplication?</p>
  
  <p>I've tried to pass the <code>result interface{}</code> param instead of creating it in the method, and call the method like this:</p>
  
  <pre><code>dao.FindAll([]*entity.User{})
  </code></pre>
  
  <p>but the <code>collection.Find().All()</code> method need a slice as the input, not just interface:</p>
  
  <pre><code>[restful] recover from panic situation: - result argument must be a slice address
  /usr/local/go/src/runtime/asm_amd64.s:514
  /usr/local/go/src/runtime/panic.go:489
  /home/dds/gopath/src/gopkg.in/mgo.v2/session.go:3791
  /home/dds/gopath/src/gopkg.in/mgo.v2/session.go:3818
  </code></pre>
  
  <p>Then I tried to make this param <code>result []interface{}</code>, but in that case it's impossible to pass <code>[]*entity.User{}</code>:</p>
  
  <blockquote>
    <p>cannot use []*entity.User literal (type []*entity.User) as type []interface {} in argument to thisDao.GenericDao.FindAll</p>
  </blockquote>
  
  <p>Any idea how could I implement generic DAO in Go?</p>