Skip to content

Commit

Permalink
fix: deferred close and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pcvolkmer committed Dec 17, 2024
1 parent 8bbf6af commit 1c8d7e4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ func main() {
}

if dbx, dbErr := initDb(dbCfg); dbErr == nil {
log.Fatalf("Cannot connect to Database: %s\n", dbErr.Error())
} else {
db = dbx
defer func(db *sql.DB) {
err := db.Close()
if err != nil {
log.Println("Cannot close database connection")
}
}(db)
} else {
log.Fatalf("Cannot connect to Database: %s\n", dbErr.Error())
}
defer func(db *sql.DB) {
err := db.Close()
if err != nil {
log.Println("Cannot close database connection")
}
}(db)

if cli.OcaPlus {
patients := InitPatients(db)
Expand Down

0 comments on commit 1c8d7e4

Please sign in to comment.