Documentation ¶
Index ¶
- Variables
- type SQLiteStore
- func (st *SQLiteStore) Cleanup(ctx context.Context, dur time.Duration) error
- func (st *SQLiteStore) Create(ctx context.Context, session sessionup.Session) error
- func (st *SQLiteStore) DeleteByID(ctx context.Context, id string) error
- func (st *SQLiteStore) DeleteByUserKey(ctx context.Context, key string, expIDs ...string) error
- func (st *SQLiteStore) FetchByID(ctx context.Context, id string) (sessionup.Session, bool, error)
- func (st *SQLiteStore) FetchByUserKey(ctx context.Context, key string) ([]sessionup.Session, error)
- func (st *SQLiteStore) OnDeletion(fn func(context.Context, sessionup.Session)) func()
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTable is returned when invalid table name is provided. ErrInvalidTable = errors.New("invalid table name") // ErrInvalidInterval is returned when invalid cleanup interval is provided. ErrInvalidInterval = errors.New("invalid cleanup interval") )
Functions ¶
This section is empty.
Types ¶
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore is a SQLite implementation of sessionup.Store.
func New ¶
func New(db *sql.DB, table string) (*SQLiteStore, error)
New creates and returns a fresh intance of SQLiteStore.
func NewWithCleanup ¶ added in v1.1.0
func NewWithCleanup( db *sql.DB, table string, dur time.Duration, ) (*SQLiteStore, <-chan error, func(), error)
NewWithCleanup creates and returns a fresh instance of SQLiteStore and additionally spins up cleanup go routine. To manage new go routine a cleanup errors channel and cleanup close delegate function is returned.
func (*SQLiteStore) Cleanup ¶ added in v1.1.0
Cleanup periodically removes all expired records from the store by their expiration time. Duration specifies how often cleanup should be ran. If duration is less than zero, an ErrInvalidInterval error will be returned.
func (*SQLiteStore) DeleteByID ¶
func (st *SQLiteStore) DeleteByID(ctx context.Context, id string) error
DeleteByID deletes the session from the store by the provided ID. If session is found OnDeletion handlers will be executed. If session is not found, this function will be no-op.
func (*SQLiteStore) DeleteByUserKey ¶
DeleteByUserKey deletes all sessions associated with the provided user key, except those whose IDs are provided as last argument. For each deleted session all OnDeletion handlers will be executed. If none are found, this function will no-op.
func (*SQLiteStore) FetchByID ¶
FetchByID retrieves a session from the store by the provided ID. The second returned value indicates whether the session was found or not (true == found), error will be nil if session is not found. If session is expired, it will be treated as not found.
func (*SQLiteStore) FetchByUserKey ¶
FetchByUserKey retrieves all sessions associated with the provided user key. If none are found, both return values will be nil. If list contains expired sessions, they will not be returned.
func (*SQLiteStore) OnDeletion ¶ added in v1.1.0
func (st *SQLiteStore) OnDeletion(fn func(context.Context, sessionup.Session)) func()
OnDeletion sets provided handler to be executed whenever a session is deleted. Unsubscribe method is returned, that allows to unset the handler.