修改数据库连接失败后的处理逻辑为报错,然后退出程序

This commit is contained in:
noreply
2024-10-14 21:20:46 +08:00
parent 392c922130
commit 67206df6a7
7 changed files with 51 additions and 34 deletions
+12 -5
View File
@@ -4,20 +4,27 @@ import (
"strings"
"github.com/spf13/viper"
"gorm.io/gorm"
)
var Mdb *gorm.DB
func DBInit() {
func DBInit() error {
dbType := viper.GetString("db_type")
if strings.EqualFold(dbType, "postgres") {
PostgreSQLInit()
if err := PostgreSQLInit(); err != nil {
return err
}
} else if strings.EqualFold(dbType, "sqlite") {
SqliteInit()
if err := SqliteInit(); err != nil {
return err
}
} else {
MysqlInit()
if err := MysqlInit(); err != nil {
return err
}
}
MdbTableInit()
return nil
}