From 64ed645e4da552703257f3a3b37bf92714368859 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 2 Jun 2020 11:09:17 +0800 Subject: [PATCH] Returns ping error --- gorm.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gorm.go b/gorm.go index 1ab3fd64..8a801d68 100644 --- a/gorm.go +++ b/gorm.go @@ -91,6 +91,17 @@ func Open(dialector Dialector, config *Config) (db *DB, err error) { if dialector != nil { err = dialector.Initialize(db) } + + if err == nil { + if pinger, ok := db.ConnPool.(interface{ Ping() error }); ok { + err = pinger.Ping() + } + } + + if err != nil { + config.Logger.Error(context.Background(), "failed to initialize database, got error %v", err) + } + return }