From 1b66859a1866039f9886416a7dd5a0d46c2f9e9d Mon Sep 17 00:00:00 2001 From: David Schneiderbauer Date: Mon, 20 May 2019 15:32:23 +0200 Subject: [PATCH] database connection check --- internal/bridge/database/database.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/bridge/database/database.go b/internal/bridge/database/database.go index 541c095..6a3b02c 100644 --- a/internal/bridge/database/database.go +++ b/internal/bridge/database/database.go @@ -45,6 +45,13 @@ func Open() (DB, error) { } dbConn, err := sql.Open(config.Bridge.DB.Driver, connURL.String()) + if err != nil { + return nil, errors.Wrap(err, "could not create db connection pool") + } - return &db{dbConn}, errors.Wrap(err, "could not connect to database server") + if err := dbConn.Ping(); err != nil { + dbConn.Close() + return nil, errors.Wrap(err, "could not connect to database server") + } + return &db{dbConn}, nil }