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.
60 lines
1.3 KiB
60 lines
1.3 KiB
// modules/auth/module.go |
|
package auth |
|
|
|
import ( |
|
"gofaster/internal/auth/controller" |
|
"gofaster/internal/auth/repository" |
|
"gofaster/internal/auth/service" |
|
"gofaster/internal/core" |
|
"gofaster/internal/shared/config" |
|
"gofaster/internal/shared/database" |
|
"gofaster/internal/shared/routes" |
|
|
|
"github.com/gin-gonic/gin" |
|
"go.uber.org/zap" |
|
"gorm.io/gorm" |
|
) |
|
|
|
type AuthModule struct { |
|
userCtrl *controller.UserController |
|
logger *zap.Logger |
|
} |
|
|
|
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 |
|
|
|
// 初始化仓库 |
|
userRepo := repository.NewUserRepo(db) |
|
roleRepo := repository.NewRoleRepo(db) |
|
permissionRepo := repository.NewPermissionRepo(db) |
|
|
|
// 初始化服务 |
|
userService := service.NewUserService(userRepo) |
|
|
|
// 初始化控制器 |
|
m.userCtrl = controller.NewUserController(userService) |
|
|
|
// 系统初始化 |
|
initService := service.NewInitService(db, userRepo, roleRepo, permissionRepo) |
|
if err := initService.InitSystem(); err != nil { |
|
return err |
|
} |
|
|
|
return nil |
|
} |
|
|
|
func (m *AuthModule) RegisterRoutes(router *gin.RouterGroup) { |
|
routes.RegisterUserRoutes(router, m.userCtrl) |
|
} |
|
|
|
func (m *AuthModule) Cleanup() { |
|
m.logger.Info("Cleaning up auth module") |
|
}
|
|
|