update: The code structure is finished, and the project can run successfully
This commit is contained in:
20
server/initialize/mysql.go
Normal file
20
server/initialize/mysql.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
)
|
||||
|
||||
//初始化数据库并产生数据库全局变量
|
||||
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)
|
||||
} else {
|
||||
global.GVA_DB = db
|
||||
global.GVA_DB.DB().SetMaxIdleConns(admin.MaxIdleConns)
|
||||
global.GVA_DB.DB().SetMaxOpenConns(admin.MaxOpenConns)
|
||||
global.GVA_DB.LogMode(admin.LogMode)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user