title: Defer on a struct sqlx.Close() ends in a stack overflow
body: <p>I just started learning Go. Lesson of the day was to wrap my database handler in a struct to avoid using global scope variables. Thought I understood it so far and wanted to defer the Close() method as I did before, which ended in an stack overflow.</p>
  <p>I couldn't find an explanation why this happen, nor what's the propper way to do this.</p>
  <p>Here is the key code:</p>
  <pre><code>package exporter
  
  type DB struct {
      *sqlx.DB
      queriesExecuted int
  }
  
  func Open(dataSourceName string) *DB {
      connection := sqlx.MustConnect(&quot;mysql&quot;, dataSourceName)
      db := &amp;DB{connection, 0}
      return db
  }
  
  func (db *DB) Close() {
      db.Close() // this is where the stack growth happens
  }
  
  func (db *DB) GetArticles() []oxarticle {
    ... 
  }
  </code></pre>
  <hr />
  <pre><code>package main
  
  func main() {
      exporter := feedexporter.Open(&quot;root:pass@/feedexport&quot;)
      defer exporter.Close()
  
      articles := exporter.GetArticles()
  }
  </code></pre>
  <p>Everything works fine without the defer exporter.Close(), including it ends in:</p>
  <blockquote>
  <p>runtime: goroutine stack exceeds 1000000000-byte limit</p>
  <p>fatal error: stack overflow</p>
  </blockquote>
  <p>It feels so bad to not close connections ;) What's the propper way to handle this?</p>