47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
// Домен авторизации.
|
||
|
|
// Этим файлом владеет команда авторизации.
|
||
|
|
//
|
||
|
|
// Что внутри: сессии, проверка токенов, логин/логаут.
|
||
|
|
// Что НЕ знает: как устроены уведомления, как устроены профили.
|
||
|
|
//
|
||
|
|
// Добавить TokenValidator? Правим ТОЛЬКО этот файл:
|
||
|
|
// 1. Добавляем тип + конструктор
|
||
|
|
// 2. Добавляем fx.Provide(newTokenValidator) в AuthModule
|
||
|
|
// 3. main.go не трогаем — ноль мерж-конфликтов
|
||
|
|
|
||
|
|
import "go.uber.org/fx"
|
||
|
|
|
||
|
|
var AuthModule = fx.Module("auth",
|
||
|
|
fx.Provide(
|
||
|
|
newSessionRepo,
|
||
|
|
newAuthService,
|
||
|
|
// newTokenValidator, ← команда добавит сюда, не в main.go
|
||
|
|
),
|
||
|
|
)
|
||
|
|
|
||
|
|
// --- SessionRepo ---
|
||
|
|
|
||
|
|
type sessionRepo struct {
|
||
|
|
db DB
|
||
|
|
cache Cache
|
||
|
|
}
|
||
|
|
|
||
|
|
func newSessionRepo(db DB, cache Cache) SessionRepository {
|
||
|
|
return &sessionRepo{db: db, cache: cache}
|
||
|
|
}
|
||
|
|
|
||
|
|
// --- AuthService ---
|
||
|
|
|
||
|
|
type authServiceImpl struct {
|
||
|
|
userRepo UserRepository
|
||
|
|
sessionRepo SessionRepository
|
||
|
|
cache Cache
|
||
|
|
events EventBus
|
||
|
|
}
|
||
|
|
|
||
|
|
func newAuthService(userRepo UserRepository, sessionRepo SessionRepository, cache Cache, events EventBus) AuthService {
|
||
|
|
return &authServiceImpl{userRepo: userRepo, sessionRepo: sessionRepo, cache: cache, events: events}
|
||
|
|
}
|