suyiiyii e7ff1dc87d
feat(user): 添加 GORM 代码生成工具并更新数据库配置
- 在项目中引入 GORM 相关依赖
- 添加 GORM代码生成工具 gen.go
- 更新 MySQL 数据库配置
- 新增 .env 文件到 .gitignore
2025-01-17 17:54:00 +08:00

29 lines
463 B
Go

package mysql
import (
"fmt"
"github.com/suyiiyii/hertz101/app/user/conf"
"os"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var (
DB *gorm.DB
err error
)
func Init() {
dsn := fmt.Sprintf(conf.GetConf().MySQL.DSN, os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"))
DB, err = gorm.Open(mysql.Open(dsn),
&gorm.Config{
PrepareStmt: true,
SkipDefaultTransaction: true,
},
)
if err != nil {
panic(err)
}
}