service

package
v0.0.0-...-345d9e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCredentialsValidatorNotFound = errors.New("credentials validator error: account not found")
	ErrCredentialsValidatorInvalid  = errors.New("credentials validator error: invalid input")
)
View Source
var (
	ErrCredentialsAreInvalid = errors.New("credentials are invalid")
	ErrSessionAlreadyExists  = errors.New("session already exists")
	ErrSessionDoesNotExist   = errors.New("session does not exist")
	ErrInternal              = errors.New("internal error occurred")
)
View Source
var (
	ErrStorageNotFound      = errors.New("session is not found in the storage")
	ErrStorageAlreadyExists = errors.New("session already exists in the storage")
)

Functions

This section is empty.

Types

type CredentialsValidator

type CredentialsValidator interface {
	Validate(ctx context.Context, phone string, password string) (uuid.UUID, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(
	logger *slog.Logger,
	storage Storage,
	credentialsValidator CredentialsValidator,
	sessionDuration time.Duration,
) *Service

func (*Service) GetExistingSession

func (s *Service) GetExistingSession(ctx context.Context, token domain.SessionToken) (domain.Session, error)

func (*Service) Login

func (s *Service) Login(ctx context.Context, phone string, password string) (domain.Session, error)

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, token domain.SessionToken) error

func (*Service) RenewSession

func (s *Service) RenewSession(ctx context.Context, token domain.SessionToken) (domain.Session, error)

type Storage

type Storage interface {
	GetByID(ctx context.Context, id uuid.UUID) (domain.Session, error)
	GetByToken(ctx context.Context, token domain.SessionToken) (domain.Session, error)
	Add(ctx context.Context, session domain.Session) error
	RemoveByID(ctx context.Context, id uuid.UUID) (domain.Session, error)
	RemoveByToken(ctx context.Context, token domain.SessionToken) (domain.Session, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL