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.
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gofaster/internal/auth/migration"
|
|
|
|
"gofaster/internal/core"
|
|
|
|
"gofaster/internal/shared/config"
|
|
|
|
"gofaster/internal/shared/database"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AuthModule struct {
|
|
|
|
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
|
|
|
|
|
|
|
|
// 运行数据库迁移
|
|
|
|
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) {
|
|
|
|
// 这里需要从其他地方获取数据库连接
|
|
|
|
// 暂时跳过路由注册,在Init阶段处理
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *AuthModule) Cleanup() {
|
|
|
|
m.logger.Info("Cleaning up auth module")
|
|
|
|
}
|