pgstore

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 7 Imported by: 1

README

sessionup-pgstore

Build status Go Report Card GoDoc

PostgreSQL session store implementation for sessionup

Installation

go get github.com/swithek/sessionup-pgstore

Usage

Create and activate a new PgStore:

db, err := sql.Open("postgres", "...")
if err != nil {
      // handle error
}

store, err := pgstore.New(db, "sessions", time.Minute * 5)
if err != nil {
      // handle error
}

manager := sessionup.NewManager(store)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PgStore

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

PgStore is a PostgreSQL implementation of sessionup.Store.

func New

func New(db *sql.DB, tName string, d time.Duration) (*PgStore, error)

New returns a fresh instance of PgStore. tName parameter determines the name of the table that will be used for sessions. If it does not exist, it will be created. Duration parameter determines how often the cleanup function wil be called to remove the expired sessions. Setting it to 0 will prevent cleanup from being activated.

func (*PgStore) CleanupErr

func (p *PgStore) CleanupErr() <-chan error

CleanupErr returns a receive-only channel to get errors produced during the automatic cleanup. NOTE: channel must be drained in order for the cleanup process to be able to continue.

func (*PgStore) Create

func (p *PgStore) Create(ctx context.Context, s sessionup.Session) error

Create implements sessionup.Store interface's Create method.

func (*PgStore) DeleteByID

func (p *PgStore) DeleteByID(ctx context.Context, id string) error

DeleteByID implements sessionup.Store interface's DeleteByID method.

func (*PgStore) DeleteByUserKey

func (p *PgStore) DeleteByUserKey(ctx context.Context, key string, expID ...string) error

DeleteByUserKey implements sessionup.Store interface's DeleteByUserKey method.

func (*PgStore) FetchByID

func (p *PgStore) FetchByID(ctx context.Context, id string) (sessionup.Session, bool, error)

FetchByID implements sessionup.Store interface's FetchByID method.

func (*PgStore) FetchByUserKey

func (p *PgStore) FetchByUserKey(ctx context.Context, key string) ([]sessionup.Session, error)

FetchByUserKey implements sessionup.Store interface's FetchByUserKey method.

func (*PgStore) StopCleanup

func (p *PgStore) StopCleanup()

StopCleanup terminates the automatic cleanup process. Useful for testing and cases when store is used only temporary. In order to restart the cleanup, new store must be created.

Jump to

Keyboard shortcuts

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