完成nacos和数据库等配置文件

This commit is contained in:
2022-05-25 18:43:49 +08:00
parent 9bb43f4484
commit af58c03c7c
9 changed files with 128 additions and 0 deletions

23
client/mysql.go Normal file
View File

@@ -0,0 +1,23 @@
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
}