feat(database): 添加数据库初始化和配置管理功能
- 实现了数据库连接初始化,支持 MySQL 和 SQLite 两种类型 - 添加了 GORM 配置构建,包含事务控制和命名策略设置 - 集成了查询日志功能,可配置是否开启 GORM 日志 - 创建了数据库配置管理模块,使用 Viper 进行配置读取 - 添加了配置文件自动生成和默认值设置功能 - 实现了配置变更监听和热更新机制 - 定义了基础配置结构体,包含服务器、数据库和 JWT 配置
This commit is contained in:
@@ -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
@@ -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配置
|
||||
|
||||
Reference in New Issue
Block a user