sessions

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxDocumentReadersCacheSize = 1

DefaultMaxDocumentReadersCacheSize is the default maximum number of document readers to keep in cache

Variables

View Source
var ErrCantCreateSession = errors.New("can not create new session")
View Source
var ErrCantCreateSessionID = fmt.Errorf("%w: generation of session id failed", ErrCantCreateSession)
View Source
var ErrGuardAlreadyRunning = errors.New("session guard already launched")
View Source
var ErrGuardNotRunning = errors.New("session guard not running")
View Source
var ErrInvalidOptionsProvided = errors.New("invalid options provided")
View Source
var ErrMaxSessionsReached = fmt.Errorf("%w: max sessions number reached", ErrCantCreateSession)
View Source
var ErrNoSessionAuthDataProvided = errors.New("no session auth data provided").WithCode(errors.CodInvalidAuthorizationSpecification)
View Source
var ErrNoSessionIDPresent = errors.New("no sessionID provided").WithCode(errors.CodInvalidAuthorizationSpecification)
View Source
var ErrNoTransactionAuthDataProvided = errors.New("no transaction auth data provided").WithCode(errors.CodInvalidAuthorizationSpecification)
View Source
var ErrNoTransactionIDPresent = errors.New("no transactionID provided").WithCode(errors.CodInvalidAuthorizationSpecification)
View Source
var ErrOngoingReadWriteTx = errors.New("only 1 read write transaction supported at once").WithCode(errors.CodSqlserverRejectedEstablishmentOfSqlSession)
View Source
var (
	ErrPaginatedDocumentReaderNotFound = errors.New("document reader not found")
)
View Source
var ErrReadOnlyTXNotAllowed = errors.New("read only transaction not allowed")
View Source
var ErrSessionAlreadyPresent = errors.New("session already present").WithCode(errors.CodInternalError)
View Source
var ErrSessionNotFound = errors.New("no session found").WithCode(errors.CodInvalidParameterValue)
View Source
var ErrTransactionNotFound = transactions.ErrTransactionNotFound
View Source
var ErrWriteOnlyTXNotAllowed = errors.New("write only transaction not allowed")

Functions

func GetSessionIDFromContext

func GetSessionIDFromContext(ctx context.Context) (string, error)

func GetTransactionIDFromContext

func GetTransactionIDFromContext(ctx context.Context) (string, error)

func NewManager

func NewManager(options *Options) (*manager, error)

Types

type Manager

type Manager interface {
	NewSession(user *auth.User, db database.DB) (*Session, error)
	SessionPresent(sessionID string) bool
	DeleteSession(sessionID string) error
	UpdateSessionActivityTime(sessionID string)
	StartSessionsGuard() error
	StopSessionsGuard() error
	GetSession(sessionID string) (*Session, error)
	SessionCount() int
	GetTransactionFromContext(ctx context.Context) (transactions.Transaction, error)
	GetSessionFromContext(ctx context.Context) (*Session, error)
	DeleteTransaction(transactions.Transaction) error
	CommitTransaction(ctx context.Context, transaction transactions.Transaction) ([]*sql.SQLTx, error)
	RollbackTransaction(transaction transactions.Transaction) error
}

type Options

type Options struct {
	SessionGuardCheckInterval time.Duration
	// MaxSessionInactivityTime is a duration for the amount of time after which an idle session would be closed by the server
	MaxSessionInactivityTime time.Duration
	// MaxSessionAgeTime is a duration for the maximum amount of time a session may exist before it will be closed by the server
	MaxSessionAgeTime time.Duration
	// Timeout the server waits for a duration of Timeout and if no activity is seen even after that the session is closed
	Timeout time.Duration
	// Max number of simultaneous sessions
	MaxSessions int
	// Random number generator
	RandSource io.Reader
}

func DefaultOptions

func DefaultOptions() *Options

func (*Options) Normalize added in v1.3.1

func (o *Options) Normalize() *Options

func (*Options) Validate added in v1.3.1

func (o *Options) Validate() error

func (*Options) WithMaxSessionAgeTime

func (o *Options) WithMaxSessionAgeTime(maxAgeTime time.Duration) *Options

func (*Options) WithMaxSessionInactivityTime

func (o *Options) WithMaxSessionInactivityTime(maxInactivityTime time.Duration) *Options

func (*Options) WithMaxSessions added in v1.3.1

func (o *Options) WithMaxSessions(maxSessions int) *Options

func (*Options) WithRandSource added in v1.3.1

func (o *Options) WithRandSource(src io.Reader) *Options

func (*Options) WithSessionGuardCheckInterval

func (o *Options) WithSessionGuardCheckInterval(interval time.Duration) *Options

func (*Options) WithTimeout

func (o *Options) WithTimeout(timeout time.Duration) *Options

type PaginatedDocumentReader added in v1.5.0

type PaginatedDocumentReader struct {
	Reader         document.DocumentReader // reader to read from
	Query          *protomodel.Query
	LastPageNumber uint32 // last read page number
	LastPageSize   uint32 // number of items per page
}

type Session

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

func NewSession

func NewSession(sessionID string, user *auth.User, db database.DB, log logger.Logger) *Session

func (*Session) CloseDocumentReaders added in v1.5.0

func (s *Session) CloseDocumentReaders() error

func (*Session) DeleteDocumentReader added in v1.5.0

func (s *Session) DeleteDocumentReader(searchID string) error

func (*Session) GetCreationTime

func (s *Session) GetCreationTime() time.Time

func (*Session) GetDatabase

func (s *Session) GetDatabase() database.DB

func (*Session) GetDocumentReader added in v1.5.0

func (s *Session) GetDocumentReader(searchID string) (*PaginatedDocumentReader, error)

func (*Session) GetDocumentReadersCount added in v1.5.0

func (s *Session) GetDocumentReadersCount() int

func (*Session) GetID

func (s *Session) GetID() string

func (*Session) GetLastActivityTime

func (s *Session) GetLastActivityTime() time.Time

func (*Session) GetTransaction

func (s *Session) GetTransaction(transactionID string) (transactions.Transaction, error)

func (*Session) GetUser

func (s *Session) GetUser() *auth.User

func (*Session) NewTransaction

func (s *Session) NewTransaction(ctx context.Context, opts *sql.TxOptions) (transactions.Transaction, error)

func (*Session) RemoveTransaction

func (s *Session) RemoveTransaction(transactionID string) error

func (*Session) RollbackTransactions

func (s *Session) RollbackTransactions() error

func (*Session) SetDatabase

func (s *Session) SetDatabase(db database.DB)

func (*Session) SetLastActivityTime

func (s *Session) SetLastActivityTime(t time.Time)

func (*Session) SetPaginatedDocumentReader added in v1.5.0

func (s *Session) SetPaginatedDocumentReader(searchID string, reader *PaginatedDocumentReader)

func (*Session) UpdatePaginatedDocumentReader added in v1.5.0

func (s *Session) UpdatePaginatedDocumentReader(searchID string, lastPage uint32, lastPageSize uint32) error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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