24 lines
478 B
Go
24 lines
478 B
Go
|
package client
|
||
|
|
||
|
import (
|
||
|
"git.echol.cn/loser/logger/log"
|
||
|
"online_code/config"
|
||
|
|
||
|
"git.echol.cn/loser/logger"
|
||
|
"gorm.io/driver/mysql"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
var MySQL *gorm.DB
|
||
|
|
||
|
func InitMySQLClient() {
|
||
|
// 创建连接对象
|
||
|
conn, err := gorm.Open(mysql.Open(config.Scd.MySQL.GetDSN()), &gorm.Config{Logger: logger.DefaultGormLogger()})
|
||
|
if err != nil {
|
||
|
log.Panic("初始化MySQL连接失败, 错误信息: %v", err)
|
||
|
} else {
|
||
|
log.Debug("MySQL连接成功")
|
||
|
}
|
||
|
MySQL = conn
|
||
|
}
|