Browse Source

Handle nil pointer dereference panic after db connect fail

main
Granty1 5 years ago
parent
commit
69742b935a
  1. 4
      server/initialize/mysql.go

4
server/initialize/mysql.go

@ -4,13 +4,15 @@ import (
"gin-vue-admin/global"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
"os"
)
//初始化数据库并产生数据库全局变量
func Mysql() {
admin := global.GVA_CONFIG.Mysql
if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
global.GVA_LOG.Error("DEFAULTDB数据库启动异常", err)
global.GVA_LOG.Error("MySQL启动异常", err)
os.Exit(0)
} else {
global.GVA_DB = db
global.GVA_DB.DB().SetMaxIdleConns(admin.MaxIdleConns)

Loading…
Cancel
Save