Returns ping error

This commit is contained in:
Jinzhu 2020-06-02 11:09:17 +08:00
parent 8bb05a5a69
commit 64ed645e4d
1 changed files with 11 additions and 0 deletions

11
gorm.go
View File

@ -91,6 +91,17 @@ func Open(dialector Dialector, config *Config) (db *DB, err error) {
if dialector != nil { if dialector != nil {
err = dialector.Initialize(db) 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 return
} }