title: Function which returns list of struct from gorm database returning nil?
body: <p>I'm trying to make a function that will output all of the contents from a table as a slice of the struct the table is.</p>
  <pre><code>func FetchAll(parameter interface{}) []interface{} {
      var model interface{}
  
      var resultArray []interface{}
  
      db := common.GetDB()
      rows, err := db.Model(parameter).Where(parameter).Rows()
      if err != nil {
          fmt.Print(err.Error())
          return nil
      }
      for rows.Next() {
          db.ScanRows(rows, &amp;model)
          resultArray = append(resultArray, model)
      }
      fmt.Println(resultArray)
      return resultArray
  }
  </code></pre>
  <p>Usage:</p>
  <pre><code>c.JSON(200, FetchAll(&amp;ProductImage{ProductID: productID}))
  </code></pre>
  <p>But the output is the following:</p>
  <pre><code>[&lt;nil&gt;,&lt;nil&gt;,&lt;nil&gt;]
  </code></pre>
  <p>Why is it?</p>