sessions

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSessions = 100

Variables

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 = errors.New("max sessions reached")
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 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(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
}

func DefaultOptions

func DefaultOptions() *Options

func (*Options) WithMaxSessionAgeTime

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

func (*Options) WithMaxSessionInactivityTime

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

func (*Options) WithSessionGuardCheckInterval

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

func (*Options) WithTimeout

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

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) GetCreationTime

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

func (*Session) GetDatabase

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

func (*Session) GetID

func (s *Session) GetID() string

func (*Session) GetLastActivityTime

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

func (*Session) GetReadWriteTxOngoing

func (s *Session) GetReadWriteTxOngoing() bool

func (*Session) GetStatus

func (s *Session) GetStatus() Status

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(mode schema.TxMode) (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) SetReadWriteTxOngoing added in v1.2.1

func (s *Session) SetReadWriteTxOngoing(b bool)

type Status

type Status int64

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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