session

package
v0.0.0-...-b33ff70 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APISession

type APISession struct {
	SessionID    int64     `json:"session_id" db:"session_id"`
	ExpiresAt    time.Time `json:"expires_at" db:"expires_at"`
	LastAccessAt time.Time `json:"last_access_at" db:"last_access_at"`
	Username     string    `json:"username" db:"username"`
	UserAgent    string    `json:"user_agent" db:"user_agent"`
	IPAddress    string    `json:"ip_address" db:"ip_address"`
}

type Cache

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

func NewCache

func NewCache(
	ctx context.Context,
	defaultExpiration,
	cleanupInterval time.Duration,
	storage StorageProvider,
	c InternalCacheProvider,
) (*Cache, error)

func (*Cache) Close

func (p *Cache) Close() error

func (*Cache) Delete

func (p *Cache) Delete(ctx context.Context, sessionID int64) error

func (*Cache) DeleteAllByUser

func (p *Cache) DeleteAllByUser(ctx context.Context, username string) (err error)

func (*Cache) DeleteByID

func (p *Cache) DeleteByID(ctx context.Context, username string, sessionID int64) (err error)

func (*Cache) DeleteExpired

func (p *Cache) DeleteExpired(ctx context.Context) error

func (*Cache) Get

func (p *Cache) Get(ctx context.Context, sessionID int64) (*APISession, error)

func (*Cache) GetAllByUser

func (p *Cache) GetAllByUser(ctx context.Context, username string) (sessions []*APISession, err error)

func (*Cache) Save

func (p *Cache) Save(ctx context.Context, session *APISession) (sessionID int64, err error)

type CleanupTask

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

func NewCleanupTask

func NewCleanupTask(c *Cache) *CleanupTask

func (*CleanupTask) Run

func (t *CleanupTask) Run(ctx context.Context) error

type InternalCacheProvider

type InternalCacheProvider interface {
	Set(k string, x interface{}, d time.Duration)
	Get(k string) (interface{}, bool)
	Delete(k string)
	ItemCount() int
	// using `cache.Item` creates a interface dependency on go-cache but currently
	// not worth de-coupling. if alternative cache implementations are required then
	// deal with this then.
	Items() map[string]cache.Item
}

current implementation provided by go-cache

type SqliteProvider

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

func NewSqliteProvider

func NewSqliteProvider(dbPath string, dataSourceOptions sqlite.DataSourceOptions) (*SqliteProvider, error)

func (*SqliteProvider) Close

func (p *SqliteProvider) Close() error

func (*SqliteProvider) Delete

func (p *SqliteProvider) Delete(ctx context.Context, sessionID int64) error

func (*SqliteProvider) DeleteAllByUser

func (p *SqliteProvider) DeleteAllByUser(ctx context.Context, username string) (err error)

func (*SqliteProvider) DeleteByID

func (p *SqliteProvider) DeleteByID(ctx context.Context, username string, sessionID int64) (err error)

func (*SqliteProvider) DeleteExpired

func (p *SqliteProvider) DeleteExpired(ctx context.Context) error

func (*SqliteProvider) Get

func (p *SqliteProvider) Get(ctx context.Context, sessionID int64) (*APISession, error)

func (*SqliteProvider) GetAll

func (p *SqliteProvider) GetAll(ctx context.Context) ([]*APISession, error)

func (*SqliteProvider) Save

func (p *SqliteProvider) Save(ctx context.Context, session *APISession) (sessionID int64, err error)

type StorageProvider

type StorageProvider interface {
	Get(ctx context.Context, sessionID int64) (*APISession, error)
	GetAll(ctx context.Context) ([]*APISession, error)
	Save(ctx context.Context, session *APISession) (sessionID int64, err error)
	Delete(ctx context.Context, sessionID int64) error
	DeleteExpired(ctx context.Context) error
	Close() error

	DeleteAllByUser(ctx context.Context, username string) (err error)
	DeleteByID(ctx context.Context, username string, sessionID int64) (err error)
}

Jump to

Keyboard shortcuts

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