Skip to content

Commit

Permalink
Fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanj committed May 29, 2016
1 parent aaae197 commit b966c04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
files/
assets/
assets
zqz
*.coverprofile
/vendor/*
5 changes: 5 additions & 0 deletions models/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"fmt"
"os"
"sync"

"github.com/lib/pq"
)
Expand All @@ -15,8 +16,12 @@ type Executor interface {
}

var database *sql.DB
var mu sync.Mutex

func GetDB() (*sql.DB, error) {
mu.Lock()
defer mu.Unlock()

var err error
if database == nil {
database, err = Connection()
Expand Down

0 comments on commit b966c04

Please sign in to comment.