title: Golang with GORM. How to correctly pass model type into method?
body: <p>I have next GORM model</p>
  
  <pre class="lang-golang prettyprint-override"><code>package entity
  
  import (
      "github.com/jinzhu/gorm"
  )
  
  type InterfaceEntity interface {
  }
  
  type User struct {
      InterfaceEntity
      gorm.Model
      Name string
  }
  </code></pre>
  
  <p>I try to pass GORM entity type into base crud repository. My base crud repository:</p>
  
  <pre><code>package repository
  
  import (
      "billingo/model/entity"
      "fmt"
      "github.com/jinzhu/gorm"
      "reflect"
  )
  
  type CrudRepository struct {
      *BaseRepository
  }
  
  func NewCrudRepository(db *gorm.DB) CrudRepositoryInterface {
      repo := NewBaseRepository(db).(*BaseRepository)
      return &amp;CrudRepository{repo}
  }
  
  func (c CrudRepository) Find(id uint, item entity.InterfaceEntity) entity.InterfaceEntity {
      fmt.Println("--- Initial")
      var local entity.User
      fmt.Println("--- local: ", reflect.TypeOf(local), local)
      fmt.Println("--- Item:  ", reflect.TypeOf(item), item)
  
  
      fmt.Println("--- Values")
      c.db.First(&amp;local, id)
      fmt.Println("--- local: ", reflect.TypeOf(local), local)
      c.db.First(&amp;item, id)
      fmt.Println("--- Item: ", reflect.TypeOf(item), item)
      return item
  }
  </code></pre>
  
  <p>As you can see here are <code>item</code> and <code>local</code> variables in <code>Find()</code> method.</p>
  
  <p>I pass <code>item</code> using next way from service:</p>
  
  <pre><code>func (c CrudService) GetItem(id uint) entity.InterfaceEntity {
      var item entity.User
      return c.repository.Find(id, item)
  }
  </code></pre>
  
  <p>It seems what <code>local</code> and <code>item</code> must be equals and behavior must be equivalent.</p>
  
  <p>But output is</p>
  
  <pre><code>--- Initial
  --- local:  entity.User {&lt;nil&gt; {0 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC &lt;nil&gt;} }
  --- Item:   entity.User {&lt;nil&gt; {0 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC &lt;nil&gt;} }
  --- Values
  --- local:  entity.User {&lt;nil&gt; {1 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC &lt;nil&gt;} test 1}
  --- Item:  entity.User {&lt;nil&gt; {0 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC &lt;nil&gt;} }
  INFO[0000] User info                                     user="{&lt;nil&gt; {0 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC &lt;nil&gt;} }" user-id=1
  
  (/home/mnv/go/src/billingo/model/repository/CrudRepository.go:29) 
  [2019-05-17 17:07:37]  unsupported destination, should be slice or struct 
  </code></pre>
  
  <p><code>item</code> passed from service leads to message</p>
  
  <blockquote>
    <p>unsupported destination, should be slice or struct</p>
  </blockquote>
  
  <p>How to pass <code>item</code> correctly, I need behavior like with <code>local</code>?</p>