From b674fc35ad25e90db13f1f5a7ae8eb08232782a7 Mon Sep 17 00:00:00 2001 From: Emile Date: Sat, 19 Oct 2019 00:55:14 +0200 Subject: setting up the database connection correctly --- src/main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.go b/src/main.go index 38f254c..4af5cc4 100644 --- a/src/main.go +++ b/src/main.go @@ -1,8 +1,8 @@ package main import ( + "database/sql" "flag" - "fmt" "log" "net/http" "os" @@ -11,6 +11,10 @@ import ( _ "github.com/lib/pq" ) +var ( + db *sql.DB +) + func main() { // Set up flags log.Println("Setting up components") @@ -22,9 +26,7 @@ func main() { httpServer := setupHTTPServer() // Set up the DB connection - db := setupDatabase() - name := getName(db) - fmt.Println(name) + db = setupDatabase() // React to system signals signalChannel := make(chan os.Signal, 1) -- cgit 1.4.1