title: Golang calling methods on interface pointer
body: <p>I am using <a href="https://github.com/coopernurse/gorp" rel="noreferrer">Gorp</a> for database access, Gorp has a standard <code>DbMap</code> type, as well as a <code>Transaction</code> type for when you want to be able to roll back. Both types implement the <code>SqlExecutor</code> interface.</p>
  
  <p>I am therefore programming against the <code>SqlExecutor</code> interface, so I can use transactions if I want without needing to change my code.</p>
  
  <p>I then initialise a Gorp <code>DbMap</code> or <code>Transaction</code> and pass it in as a field property. The problem is that I need a pointer to the Gorp "object", else how will I be able to roll back if I use a <code>Transaction</code> if the Gorp "object" is passed by value instead of reference.</p>
  
  <p>I then get a message such as </p>
  
  <pre><code>r.Gorp.Get undefined (type *gorp.SqlExecutor has no field or method Get)
  </code></pre>
  
  <p>when I try use my code. How do I call the methods?</p>
  
  <p>A code sample is below.</p>
  
  <pre><code>package repositories
  
  import (
      "github.com/coopernurse/gorp"
  )
  
  
  type Repository struct {
      Gorp *gorp.SqlExecutor // &lt;&lt;&lt;&lt; Need pointer so I can rollback
  }
  
  func (r *Repository) GetById(i interface{}, key interface{}) interface{} {
      obj, err := r.Gorp.Get(i, key)
      if err != nil {
          panic(err)
      }
      return obj
  }
  </code></pre>