boltstore

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2020 License: MIT Imports: 8 Imported by: 0

README

sessionup-boltstore

GoDoc Test coverage Go Report Card

This is an Bolt session store implementation for sessionup

Installation

To install simply use:

go get github.com/davseby/sessionup-boltstore

Usage

To create and use new BoltStore use New method. It accepts three parameters, the first one being an open bolt database. Then a bucket name is required in which sessions will be stored and managed. The bucket parameter cannot be an empty string. Lastly it is required that you specify the duration between cleanup intervals, if the provided value is zero the cleanup process won't be started. It cannot be less than zero.

db, err := bolt.Open("my.db", 0600, nil)
if err != nil {
      // handle error
}

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

manager := sessionup.NewManager(store)

Don't forget to handle cleanup errors by using CleanupErr method. Channel should be used only for receiving errors. Whenever the cleanup service is active, errors from this channel will have to be drained, otherwise cleanup won't be able to continue its process.

for {
      select {
            case err := <-store.CleanupErr():
                  // handle err
      }
}

If you want to close auto cleanup process simply use Close method. It won't close the database so you will still be able to use all of the methods described by the sessionup store interface. It will always return nil as an error, implements io.Closer interface.

store.Close()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidBucket is returned when invalid bucket name is provided.
	ErrInvalidBucket = errors.New("invalid bucket name")

	// ErrInvalidInterval is returned when invalid cleanup interval is provided.
	ErrInvalidInterval = errors.New("invalid cleanup interval")
)

Functions

This section is empty.

Types

type BoltStore

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

BoltStore is a bolt implementation of sessionup.Store.

func New

func New(db *bolt.DB, bucket string, cleanupInterval time.Duration) (*BoltStore, error)

New creates and returns a fresh intance of BoltStore. Bucket parameter determines bucket name which is used to store and manage sessions, it cannot be an empty string. Cleanup interval parameter is an interval time between each clean up. If this interval is equal to zero, cleanup won't be executed. Cannot be less than zero.

func (BoltStore) CleanupErr

func (b BoltStore) CleanupErr() <-chan error

CleanupErr returns a channel that should be used to read and handle errors that occured during cleanup process. Whenever the cleanup service is active, errors from this channel will have to be drained, otherwise cleanup won't be able to continue its process.

func (*BoltStore) Close

func (b *BoltStore) Close() error

Close stops the cleanup service. It always returns nil as an error, used to implement io.Closer interface.

func (*BoltStore) Create

func (b *BoltStore) Create(_ context.Context, s sessionup.Session) error

Create inserts provided session into the store and ensures that it is deleted when expiration time is due.

func (*BoltStore) DeleteByID

func (b *BoltStore) DeleteByID(_ context.Context, id string) error

DeleteByID deletes the session from the store by the provided ID. If session is not found, this function will be no-op.

func (*BoltStore) DeleteByUserKey

func (b *BoltStore) DeleteByUserKey(_ context.Context, key string, expIDs ...string) error

DeleteByUserKey deletes all sessions associated with the provided user key, except those whose IDs are provided as last argument. If none are found, this function will no-op.

func (*BoltStore) FetchByID

func (b *BoltStore) FetchByID(_ context.Context, id string) (sessionup.Session, bool, error)

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.

func (*BoltStore) FetchByUserKey

func (b *BoltStore) FetchByUserKey(_ context.Context, key string) ([]sessionup.Session, error)

FetchByUserKey retrieves all sessions associated with the provided user key. If none are found, both return values will be nil.

Jump to

Keyboard shortcuts

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