add admin router

This commit is contained in:
张超
2025-06-18 18:34:08 +08:00
parent 67c85327ee
commit 4c9f6c140f
4 changed files with 32 additions and 86 deletions

View File

@@ -32,10 +32,6 @@ type DataBaseConfig struct {
MaxConns int `mapstructure:"max_conns"`
}
type Jwt struct {
SecretKey string
}
type Project struct {
StaticUrlMapPath []interface{}
TemplateGlob string
@@ -56,17 +52,15 @@ type ThemeConfig struct {
AllowUpload bool `mapstructure:"allow_upload"`
}
type SecurityConfig struct {
JWTSecret string `mapstructure:"jwt_secret"`
CORSAllowedOrigins []string `mapstructure:"cors_allowed_origins"`
}
type Config struct {
Env string
Server ServerConfig
DataBase DataBaseConfig
Theme ThemeConfig
JwtSecretKey Jwt
Project Project
Security SecurityConfig
Env string
Server ServerConfig
DataBase DataBaseConfig
Theme ThemeConfig
Project Project
Security SecurityConfig
}
var globalConfig *Config // 新增全局配置变量
@@ -109,11 +103,6 @@ func LoadConfig(configPath string) (*Config, error) {
return nil, fmt.Errorf("配置解析失败: %w", err)
}
// 6. 校验必要配置项
// if cfg.Security.JWTSecret == "" {
// return nil, fmt.Errorf("安全配置错误: jwt_secret 必须设置")
// }
// 获取配置值
mysqlHost := viper.GetString("database.Host")
jwtSecretKey := viper.GetString("jwt.SecretKey")
@@ -128,25 +117,3 @@ func LoadConfig(configPath string) (*Config, error) {
globalConfig = &cfg // 保存配置到全局变量
return &cfg, nil
}
func GetCurrentTheme() string {
return "default"
}
func SetCurrentTheme(theme string) error {
return nil
}
// GetJWTSecret 获取 JWT 密钥
// 移除原有的方法定义(如果存在)
// func (c *Config) GetJWTSecret() string {
// 原错误:返回 security.JWTSecret实际应使用 jwtSecretKey.SecretKey
// }
// 新增包级函数获取 JWT 密钥
func GetJWTSecret() string {
if globalConfig == nil {
//panic("配置未加载,请先调用 LoadConfig")
}
return globalConfig.JwtSecretKey.SecretKey
}