feat(auth+db): 实现注册登录核心逻辑,以及自动建表,用户信息落库

This commit is contained in:
2026-05-24 13:53:03 +08:00
parent afb33d4d5d
commit 7c0ce6fce8
9 changed files with 198 additions and 23 deletions
+21 -1
View File
@@ -8,9 +8,12 @@ import (
// Config 应用全局配置,优先读取环境变量,未设置时使用默认值。
type Config struct {
Port int // HTTP 监听端口,默认 8080,环境变量 GEN2D_PORT
Port int // HTTP 监听端口,默认 8080,环境变量 GEN2D_PORT
Mode string // Gin 运行模式 (debug/release),环境变量 GEN2D_MODE
MaxFileSize int64 // 上传文件大小上限(字节),默认 10MB
DSN string // SQLite 数据库路径,默认 data/gen2d.db,环境变量 GEN2D_DSN
JWTSecret string // JWT 签名密钥,环境变量 GEN2D_JWT_SECRET
JWTExpire int64 // JWT 过期时间(秒),默认 7200
}
// Load 从环境变量加载配置并返回。
@@ -19,6 +22,9 @@ func Load() *Config {
Port: 8080,
Mode: "debug",
MaxFileSize: 10 << 20, // 10MB
DSN: "data/gen2d.db",
JWTSecret: "gen2d-dev-secret",
JWTExpire: 7200,
}
if port := os.Getenv("GEN2D_PORT"); port != "" {
@@ -31,5 +37,19 @@ func Load() *Config {
cfg.Mode = mode
}
if dsn := os.Getenv("GEN2D_DSN"); dsn != "" {
cfg.DSN = dsn
}
if secret := os.Getenv("GEN2D_JWT_SECRET"); secret != "" {
cfg.JWTSecret = secret
}
if expire := os.Getenv("GEN2D_JWT_EXPIRE"); expire != "" {
if e, err := strconv.ParseInt(expire, 10, 64); err == nil {
cfg.JWTExpire = e
}
}
return cfg
}