title: Does db.Close() need to be called?
body: <p>So far the hardest part of Go has been understanding how to organize code.  It seems incredibly simple on it's face but every time I've tried to do anything I run into circular imports or things like "exported func Start returns unexported type models.dbStore, which can be annoying to use".</p>
  
  <p>Using the following code how do I call <code>db.Close()</code> or am I really not understanding how I'm supposed to provide the database to my models.  Here's what I've got:</p>
  
  <p>App.go</p>
  
  <pre><code>package app
  
  import (
      "database/sql"
  
      // Comment
      _ "github.com/mattn/go-sqlite3"
  )
  
  var (
      // DB The database connection
      db *sql.DB
  )
  
  // Setup Sets up the many many app settings
  func Setup() {
      d, err := sql.Open("sqlite3", "./foo.db")
      if err != nil {
          panic(err)
      }
  
      // TODO: How does the DB get closed?
      // defer db.Close()
      db = d
  }
  
  // GetDB Returns a reference to the database
  func GetDB() *sql.DB {
      return db
  }
  </code></pre>
  
  <p>Users.go</p>
  
  <pre><code>package models
  
  import (
      "github.com/proj/org/app"
  )
  
  // User struct
  type User struct {
      ID int
  }
  
  // CreateUser Creates a user
  func (u *User) CreateUser() (int64, error) {
  
      // For the sake of brevity just make sure you can
      // "connect" to the database
      if err := app.GetDB().Ping(); err != nil {
          panic(err)
      }
  
      return 1234, nil
  }
  </code></pre>
  
  <p>main.go</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "net/http"
  
      _ "github.com/mattn/go-sqlite3"
      "github.com/proj/org/app"
      "github.com/proj/org/models"
  )
  
  func homeHandler(w http.ResponseWriter, r *http.Request) {
      fmt.Fprintf(w, "You are home")
  }
  
  func subscribeHandler(w http.ResponseWriter, r *http.Request) {
      fmt.Fprintf(w, "Subscribing...")
      u := models.User{}
  
      u.CreateUser()
  
  }
  
  func main() {
      fmt.Println("Running")
  
      app.Setup()
  
      http.HandleFunc("/", homeHandler)
      http.HandleFunc("/subscribe", subscribeHandler)
  
      err := http.ListenAndServe(":9090", nil)
      if err != nil {
          panic(err)
      }
  }
  </code></pre>
  
  <p>I thought about doing a <code>app.Shutdown()</code> but that wouldn't work for my most normal use case which is CTRL-C.  It would seem if I don't close the database the DB connections would just grow... Just trying to understand.</p>