Skip to content

Commit

Permalink
Handle nil pointer dereference panic after db connect fail
Browse files Browse the repository at this point in the history
  • Loading branch information
granty1 committed Apr 25, 2020
1 parent 0d7a291 commit 69742b9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/initialize/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 69742b9

Please sign in to comment.