Skip to content

Commit aa1e472

Browse files
authored
Merge pull request #37 from hidevopsio/refactor/instance-scope
fixes the issue that app creash caused by nil sql client
2 parents e01cf9a + e965385 commit aa1e472

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

starter/gorm/autoconfigure.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func (c *configuration) DB() (db *DB, err error) {
9090
log.Errorf("failed to connect %v, err: %v", report, err)
9191
return
9292
}
93-
94-
if sqlDB.Ping() == nil {
93+
sqlDB, err = db.DB.DB()
94+
if err == nil && sqlDB.Ping() == nil {
9595
// If the connection is alive, assign the new connection
9696
c.db = db
9797
log.Infof("%v is connected", report)

starter/sqlx/autoconfigure.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ func (c *configuration) DB() (db *DB, err error) {
8787
log.Errorf("failed to connect db: %v", err)
8888
return
8989
}
90-
91-
if sqlDB.Ping() == nil {
90+
if db.DB.Ping() == nil {
9291
// If the connection is alive, assign the new connection
9392
c.db = db
9493
log.Infof("%v is connected", report)

0 commit comments

Comments
 (0)