diff options
author | Emile <hanemile@protonmail.com> | 2019-10-18 23:37:41 +0200 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-10-18 23:37:41 +0200 |
commit | c8c6400944a880da424c97c36410767290771644 (patch) | |
tree | 31a9b506586a7d5cbb529423d2735d5c714cdc97 /src | |
parent | 55acb46da2450116834ef2357d01925fdcee09a3 (diff) |
outsourced the creation of the database connection
Diffstat (limited to 'src')
-rw-r--r-- | src/main.go | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/main.go b/src/main.go index 2c99242..38f254c 100644 --- a/src/main.go +++ b/src/main.go @@ -1,7 +1,6 @@ package main import ( - "database/sql" "flag" "fmt" "log" @@ -22,31 +21,16 @@ func main() { log.Printf("Running HTTP server on port %d", *port) httpServer := setupHTTPServer() + // Set up the DB connection + db := setupDatabase() + name := getName(db) + fmt.Println(name) + // React to system signals signalChannel := make(chan os.Signal, 1) signal.Notify(signalChannel) go cleanup(signalChannel, httpServer) - //////////////////////////////////////////////////////////////////////////////// - - connStr := "user=postgres dbname=postgres sslmode=disable" - db, err := sql.Open("postgres", connStr) - if err != nil { - log.Fatal(err) - } - - // get the current name of the challenges - query := fmt.Sprintf("SELECT name FROM challenges") - var name string - err = db.QueryRow(query).Scan(&name) - if err != nil { - log.Fatalf("[ E ] :", err) - } - - fmt.Println(name) - - //////////////////////////////////////////////////////////////////////////////// - // Start our HTTP server log.Fatalln(httpServer.ListenAndServe()) } |