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:
@ -13,11 +13,8 @@ database:
|
|||||||
dbname: metalab_dev
|
dbname: metalab_dev
|
||||||
sslmode: disable
|
sslmode: disable
|
||||||
|
|
||||||
jwt:
|
# 会话配置(服务端 Session,滑动窗口续期)
|
||||||
secret: "" # 生产环境通过 JWT_SECRET 环境变量或 .env 注入(若未来需复用 JWT)
|
# 每次请求自动续期,解决"记住我"掉线问题
|
||||||
|
|
||||||
# 会话配置(服务端 Session,替换 JWT 无状态认证)
|
|
||||||
# 每次请求自动续期(滑动窗口),解决"记住我"掉线问题
|
|
||||||
session:
|
session:
|
||||||
idle_timeout: 1440 # 不记住我:空闲超时(分钟),默认 1440 = 24 小时
|
idle_timeout: 1440 # 不记住我:空闲超时(分钟),默认 1440 = 24 小时
|
||||||
remember_timeout: 43200 # 记住我:空闲超时(分钟),默认 43200 = 30 天
|
remember_timeout: 43200 # 记住我:空闲超时(分钟),默认 43200 = 30 天
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Server ServerConfig `mapstructure:"server"`
|
Server ServerConfig `mapstructure:"server"`
|
||||||
Database DatabaseConfig `mapstructure:"database"`
|
Database DatabaseConfig `mapstructure:"database"`
|
||||||
JWT JWTConfig `mapstructure:"jwt"`
|
|
||||||
Session SessionConfig `mapstructure:"session"`
|
Session SessionConfig `mapstructure:"session"`
|
||||||
Bcrypt BcryptConfig `mapstructure:"bcrypt"`
|
Bcrypt BcryptConfig `mapstructure:"bcrypt"`
|
||||||
Roles RolesConfig `mapstructure:"roles"`
|
Roles RolesConfig `mapstructure:"roles"`
|
||||||
@ -42,11 +41,7 @@ type DatabaseConfig struct {
|
|||||||
SSLMode string `mapstructure:"sslmode"`
|
SSLMode string `mapstructure:"sslmode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JWTConfig struct {
|
// SessionConfig 服务端会话配置
|
||||||
Secret string `mapstructure:"secret"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SessionConfig 服务端会话配置(替换 JWT 无状态认证)
|
|
||||||
type SessionConfig struct {
|
type SessionConfig struct {
|
||||||
IdleTimeout int `mapstructure:"idle_timeout"` // 不记住我:空闲超时(分钟),默认 1440(24小时)
|
IdleTimeout int `mapstructure:"idle_timeout"` // 不记住我:空闲超时(分钟),默认 1440(24小时)
|
||||||
RememberTimeout int `mapstructure:"remember_timeout"` // 记住我:空闲超时(分钟),默认 43200(30天)
|
RememberTimeout int `mapstructure:"remember_timeout"` // 记住我:空闲超时(分钟),默认 43200(30天)
|
||||||
@ -132,7 +127,6 @@ func loadEnvFile(path string) {
|
|||||||
// bindEnvOverride 将环境变量映射到 config 的嵌套键
|
// bindEnvOverride 将环境变量映射到 config 的嵌套键
|
||||||
func bindEnvOverride(v *viper.Viper) {
|
func bindEnvOverride(v *viper.Viper) {
|
||||||
_ = v.BindEnv("database.password", "DATABASE_PASSWORD")
|
_ = v.BindEnv("database.password", "DATABASE_PASSWORD")
|
||||||
_ = v.BindEnv("jwt.secret", "JWT_SECRET")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DSN 返回 PostgreSQL 连接字符串
|
// DSN 返回 PostgreSQL 连接字符串
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
package middleware
|
|
||||||
|
|
||||||
// auth_parser.go: JWT 解析逻辑已被服务端 Session 替换,本文件保留占位,后续清理。
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
package middleware
|
|
||||||
|
|
||||||
// auth_token.go: JWT 解析逻辑已被服务端 Session 替换,本文件保留占位,后续清理。
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
package middleware
|
|
||||||
|
|
||||||
// repository.go: JWT tokenVersionStore 接口已随 Session 迁移移除,保留占位,后续清理。
|
|
||||||
@ -12,9 +12,8 @@ type User struct {
|
|||||||
Avatar string `gorm:"type:varchar(500);default:''" json:"avatar"`
|
Avatar string `gorm:"type:varchar(500);default:''" json:"avatar"`
|
||||||
Bio string `gorm:"type:text" json:"bio"`
|
Bio string `gorm:"type:text" json:"bio"`
|
||||||
|
|
||||||
Role string `gorm:"type:varchar(20);default:user;index;not null" json:"role"`
|
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"`
|
Status string `gorm:"type:varchar(20);default:active;index;not null" json:"status"`
|
||||||
TokenVersion int `gorm:"default:0;not null" json:"-"` // 令牌版本,+1 即时吊销所有 JWT
|
|
||||||
|
|
||||||
// 安全与审计
|
// 安全与审计
|
||||||
RegIP string `gorm:"type:varchar(45);default:''" json:"-"` // 注册 IP
|
RegIP string `gorm:"type:varchar(45);default:''" json:"-"` // 注册 IP
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
// provider.go: tokenProvider 接口已移除,JWT 被服务端 Session 替换。
|
|
||||||
// 本文件保留占位,后续清理。
|
|
||||||
@ -12,11 +12,6 @@ type userAuthStore interface {
|
|||||||
ExistsByUsername(username string) (bool, error)
|
ExistsByUsername(username string) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// userTokenStore 已废弃(JWT 替换为 Session),保留占位
|
|
||||||
type userTokenStore interface {
|
|
||||||
FindByIDForAuth(userID uint) (*model.User, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// userAdminStore AdminService 所需的最小仓储接口(ISP:7 个方法)
|
// userAdminStore AdminService 所需的最小仓储接口(ISP:7 个方法)
|
||||||
type userAdminStore interface {
|
type userAdminStore interface {
|
||||||
CountSearchUsers(keyword, role, status string) (int64, error)
|
CountSearchUsers(keyword, role, status string) (int64, error)
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
// token_service.go: JWT 签发与刷新逻辑已被服务端 Session 替换,本文件保留占位,后续清理。
|
|
||||||
Reference in New Issue
Block a user