使用ai修复,暂未完成。
This commit is contained in:
@@ -69,6 +69,8 @@ type Config struct {
|
||||
Security SecurityConfig
|
||||
}
|
||||
|
||||
var globalConfig *Config // 新增全局配置变量
|
||||
|
||||
func LoadConfig(configPath string) (*Config, error) {
|
||||
// 1. 基础配置
|
||||
viper.SetConfigFile(configPath)
|
||||
@@ -123,6 +125,7 @@ func LoadConfig(configPath string) (*Config, error) {
|
||||
fmt.Printf("Server Port: %d\n", serverPort)
|
||||
fmt.Printf("TemplateGlob: %s\n", templateGlob)
|
||||
|
||||
globalConfig = &cfg // 保存配置到全局变量
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
@@ -134,7 +137,15 @@ func SetCurrentTheme(theme string) {
|
||||
}
|
||||
|
||||
// GetJWTSecret 获取 JWT 密钥
|
||||
func (c *Config) GetJWTSecret() string {
|
||||
//return c.JWT.Secret
|
||||
return c.Security.JWTSecret
|
||||
// 移除原有的方法定义(如果存在)
|
||||
// func (c *Config) GetJWTSecret() string {
|
||||
// 原错误:返回 security.JWTSecret,实际应使用 jwtSecretKey.SecretKey
|
||||
// }
|
||||
|
||||
// 新增包级函数获取 JWT 密钥
|
||||
func GetJWTSecret() string {
|
||||
if globalConfig == nil {
|
||||
panic("配置未加载,请先调用 LoadConfig")
|
||||
}
|
||||
return globalConfig.JwtSecretKey.SecretKey
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user