import
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package repository
|
||||
|
||||
import "log/slog"
|
||||
|
||||
// SessionDB — интерфейс базы данных, который нужен SessionRepo.
|
||||
// Включает BeginTx — для атомарного создания/удаления сессий.
|
||||
type SessionDB interface {
|
||||
Query(query string) error
|
||||
Exec(query string) error
|
||||
BeginTx() error
|
||||
}
|
||||
|
||||
// SessionCache — интерфейс кэша, который нужен SessionRepo.
|
||||
type SessionCache interface {
|
||||
Get(key string) (string, error)
|
||||
Set(key, value string) error
|
||||
}
|
||||
|
||||
// SessionRepo — интерфейс репозитория сессий.
|
||||
// Структура неэкспортируемая — создать объект можно только через NewSessionRepo.
|
||||
type SessionRepo interface{}
|
||||
|
||||
// sessionRepo — репозиторий сессий.
|
||||
type sessionRepo struct {
|
||||
db SessionDB
|
||||
cache SessionCache
|
||||
}
|
||||
|
||||
// NewSessionRepo создаёт репозиторий сессий.
|
||||
func NewSessionRepo(db SessionDB, cache SessionCache) SessionRepo {
|
||||
slog.Info("репозиторий сессий создан")
|
||||
return &sessionRepo{db: db, cache: cache}
|
||||
}
|
||||
Reference in New Issue
Block a user