修改数据库连接失败后的处理逻辑为报错,然后退出程序
This commit is contained in:
+12
-5
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user