You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.3 KiB
92 lines
2.3 KiB
package auth |
|
|
|
import ( |
|
"log" |
|
|
|
"gofaster/internal/auth/controller" |
|
"gofaster/internal/auth/repository" |
|
"gofaster/internal/auth/routes" |
|
"gofaster/internal/auth/service" |
|
"gofaster/internal/core" |
|
"gofaster/internal/shared/config" |
|
"gofaster/internal/shared/database" |
|
|
|
"github.com/gin-gonic/gin" |
|
"go.uber.org/zap" |
|
"gorm.io/gorm" |
|
) |
|
|
|
// Module 认证模块 |
|
type Module struct { |
|
userController *controller.UserController |
|
authController *controller.AuthController |
|
passwordController *controller.PasswordController |
|
db *gorm.DB |
|
} |
|
|
|
// NewModule 创建新的认证模块 |
|
func NewModule() *Module { |
|
return &Module{} |
|
} |
|
|
|
// Name 获取模块名称 |
|
func (m *Module) Name() string { |
|
return "auth" |
|
} |
|
|
|
// Init 初始化模块 |
|
func (m *Module) Init(cfg *config.Config, logger *zap.Logger, db *gorm.DB, redis *database.RedisClient) error { |
|
m.db = db |
|
|
|
// 初始化仓库 |
|
userRepo := repository.NewUserRepository(db) |
|
passwordPolicyRepo := repository.NewPasswordPolicyRepository(db) |
|
passwordHistoryRepo := repository.NewPasswordHistoryRepository(db) |
|
passwordResetRepo := repository.NewPasswordResetRepository(db) |
|
|
|
// 初始化服务 |
|
userService := service.NewUserService(userRepo, db) |
|
authService := service.NewAuthService(userRepo) |
|
passwordService := service.NewPasswordService( |
|
userRepo, |
|
passwordPolicyRepo, |
|
passwordHistoryRepo, |
|
passwordResetRepo, |
|
) |
|
|
|
// 初始化控制器 |
|
m.userController = controller.NewUserController(userService) |
|
m.authController = controller.NewAuthController(authService) |
|
m.passwordController = controller.NewPasswordController(passwordService, userService) |
|
|
|
log.Printf("✅ 认证模块初始化完成") |
|
return nil |
|
} |
|
|
|
// Start 启动模块 |
|
func (m *Module) Start(cfg interface{}, db *database.Database) error { |
|
// 这个方法在新接口中不再需要,保留是为了兼容性 |
|
return nil |
|
} |
|
|
|
// Stop 停止模块 |
|
func (m *Module) Stop() error { |
|
return nil |
|
} |
|
|
|
// Cleanup 清理模块资源 |
|
func (m *Module) Cleanup() { |
|
// 清理资源 |
|
} |
|
|
|
// RegisterRoutes 注册路由 |
|
func (m *Module) RegisterRoutes(router *gin.RouterGroup) { |
|
// 注册认证相关路由 |
|
routes.RegisterAuthRoutes(router, m.db) |
|
} |
|
|
|
// init 函数,在包导入时自动执行 |
|
func init() { |
|
// 注册模块类型到核心模块发现系统 |
|
core.RegisterModuleType(&Module{}) |
|
}
|
|
|