chore: 清理 JWT 向后兼容残留,移除全部死代码

- 删除 5 个空壳占位文件:auth_token.go/auth_parser.go/repository.go(middleware)/token_service.go/provider.go
- 移除 Config.JWT 字段、JWTConfig 结构体、JWT_SECRET 环境变量绑定
- 移除 config.yaml 中的 jwt 配置段
- 移除 model.User.TokenVersion 字段(session DestroyByUID 替代)
- 移除 service/repository.go 中已废弃的 userTokenStore 接口
This commit is contained in:
2026-05-30 23:42:27 +08:00
parent d9ba1cdf28
commit e3853071d6
9 changed files with 5 additions and 36 deletions

View File

@ -13,7 +13,6 @@ import (
type Config struct {
Server ServerConfig `mapstructure:"server"`
Database DatabaseConfig `mapstructure:"database"`
JWT JWTConfig `mapstructure:"jwt"`
Session SessionConfig `mapstructure:"session"`
Bcrypt BcryptConfig `mapstructure:"bcrypt"`
Roles RolesConfig `mapstructure:"roles"`
@ -42,11 +41,7 @@ type DatabaseConfig struct {
SSLMode string `mapstructure:"sslmode"`
}
type JWTConfig struct {
Secret string `mapstructure:"secret"`
}
// SessionConfig 服务端会话配置(替换 JWT 无状态认证)
// SessionConfig 服务端会话配置
type SessionConfig struct {
IdleTimeout int `mapstructure:"idle_timeout"` // 不记住我:空闲超时(分钟),默认 144024小时
RememberTimeout int `mapstructure:"remember_timeout"` // 记住我:空闲超时(分钟),默认 4320030天
@ -132,7 +127,6 @@ func loadEnvFile(path string) {
// bindEnvOverride 将环境变量映射到 config 的嵌套键
func bindEnvOverride(v *viper.Viper) {
_ = v.BindEnv("database.password", "DATABASE_PASSWORD")
_ = v.BindEnv("jwt.secret", "JWT_SECRET")
}
// DSN 返回 PostgreSQL 连接字符串

View File

@ -1,3 +0,0 @@
package middleware
// auth_parser.go: JWT 解析逻辑已被服务端 Session 替换,本文件保留占位,后续清理。

View File

@ -1,3 +0,0 @@
package middleware
// auth_token.go: JWT 解析逻辑已被服务端 Session 替换,本文件保留占位,后续清理。

View File

@ -1,3 +0,0 @@
package middleware
// repository.go: JWT tokenVersionStore 接口已随 Session 迁移移除,保留占位,后续清理。

View File

@ -12,9 +12,8 @@ type User struct {
Avatar string `gorm:"type:varchar(500);default:''" json:"avatar"`
Bio string `gorm:"type:text" json:"bio"`
Role string `gorm:"type:varchar(20);default:user;index;not null" json:"role"`
Status string `gorm:"type:varchar(20);default:active;index;not null" json:"status"`
TokenVersion int `gorm:"default:0;not null" json:"-"` // 令牌版本,+1 即时吊销所有 JWT
Role string `gorm:"type:varchar(20);default:user;index;not null" json:"role"`
Status string `gorm:"type:varchar(20);default:active;index;not null" json:"status"`
// 安全与审计
RegIP string `gorm:"type:varchar(45);default:''" json:"-"` // 注册 IP

View File

@ -1,4 +0,0 @@
package service
// provider.go: tokenProvider 接口已移除JWT 被服务端 Session 替换。
// 本文件保留占位,后续清理。

View File

@ -12,11 +12,6 @@ type userAuthStore interface {
ExistsByUsername(username string) (bool, error)
}
// userTokenStore 已废弃JWT 替换为 Session保留占位
type userTokenStore interface {
FindByIDForAuth(userID uint) (*model.User, error)
}
// userAdminStore AdminService 所需的最小仓储接口ISP7 个方法)
type userAdminStore interface {
CountSearchUsers(keyword, role, status string) (int64, error)

View File

@ -1,3 +0,0 @@
package service
// token_service.go: JWT 签发与刷新逻辑已被服务端 Session 替换,本文件保留占位,后续清理。