feat(database): 添加数据库初始化和配置管理功能

- 实现了数据库连接初始化,支持 MySQL 和 SQLite 两种类型
- 添加了 GORM 配置构建,包含事务控制和命名策略设置
- 集成了查询日志功能,可配置是否开启 GORM 日志
- 创建了数据库配置管理模块,使用 Viper 进行配置读取
- 添加了配置文件自动生成和默认值设置功能
- 实现了配置变更监听和热更新机制
- 定义了基础配置结构体,包含服务器、数据库和 JWT 配置
This commit is contained in:
maguodong
2026-03-28 13:57:31 +08:00
parent ed7d18a72a
commit 3209cfe830
3 changed files with 22 additions and 7 deletions
+1
View File
@@ -60,6 +60,7 @@ func SetDefault() {
viper.Set("SERVER.mode", "release")
viper.Set("DATABASE.type", "sqlite")
viper.Set("DATABASE.dns", gfile.Join(gfile.Pwd(), "db", "database.db"))
viper.Set("DATABASE.debug", true)
viper.Set("JWT.secret", "SET-YOUR-SECRET")
viper.Set("JWT.expire", 86400)
}
+3 -2
View File
@@ -15,8 +15,9 @@ type ServerConfig struct {
// DataBaseConfig 数据库配置
type DataBaseConfig struct {
Dns string `mapstructure:"dns"`
Type string `mapstructure:"type"`
Dns string `mapstructure:"dns"`
Type string `mapstructure:"type"`
Debug bool `mapstructure:"debug"` // 是否开启 GORM 查询日志
}
// JwtConfig JWT配置