summaryrefslogtreecommitdiff
path: root/backend/main.go
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-28 07:55:00 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-28 07:55:00 -0500
commit4a7b855e85eb9e1dd04c7d9b0ede1f387bee31bc (patch)
treeaa674eb0dab1a3502bcfa2d15020a315f7f8b483 /backend/main.go
parent510f3d83f0da041e90d358c796eb0c209b265f30 (diff)
Fix error handling on database connect
Now panics when can't connect to database and splits handling of errors from Open() and Ping() as separate issues.
Diffstat (limited to 'backend/main.go')
-rw-r--r--backend/main.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/backend/main.go b/backend/main.go
index 0d22b80..9639b74 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -317,8 +317,13 @@ func main() {
dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_NAME)
db, err = sql.Open("postgres", dbinfo)
- if err != nil || db.Ping() != nil {
- fmt.Println("Error connecting to database")
+ if err != nil {
+ panic(err)
+ }
+
+ err = db.Ping()
+ if err != nil {
+ panic(err)
}
http.HandleFunc("/recipes", RecipeList)