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.
 
 
 
 
 
 

58 lines
1.2 KiB

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
}
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
// 运行数据库迁移
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: "your-secret-key", // 这里应该从配置中获取
Issuer: "gofaster",
})
}
func (m *AuthModule) Cleanup() {
m.logger.Info("Cleaning up auth module")
}