package auth import ( "gofaster/internal/auth/migration" "gofaster/internal/auth/routes" "gofaster/internal/core" "gofaster/internal/shared/config" "gofaster/internal/shared/database" "gofaster/internal/shared/middleware" "github.com/gin-gonic/gin" "go.uber.org/zap" "gorm.io/gorm" ) type AuthModule struct { logger *zap.Logger db *gorm.DB config *config.Config } func init() { core.RegisterModuleType(&AuthModule{}) } func (m *AuthModule) Name() string { return "auth" } func (m *AuthModule) Init(config *config.Config, logger *zap.Logger, db *gorm.DB, redis *database.RedisClient) error { m.logger = logger m.db = db m.config = config // 运行数据库迁移 if err := migration.RunMigrations(db); err != nil { logger.Error("Failed to run auth migrations", zap.Error(err)) return err } logger.Info("Auth module initialized successfully") return nil } func (m *AuthModule) RegisterRoutes(router *gin.RouterGroup) { if m.db == nil { m.logger.Error("Database connection not available for auth routes") return } // 注册认证路由 routes.RegisterAuthRoutes(router, m.db, middleware.JWTConfig{ SecretKey: m.config.JWT.Secret, // 从配置中获取JWT密钥 Issuer: m.config.JWT.Issuer, // 从配置中获取JWT发行者 }) } func (m *AuthModule) Cleanup() { m.logger.Info("Cleaning up auth module") }