boltstore

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 15 Imported by: 0

README

BoltStore - Session store using BoltDB

Overview

BoltStore is a session store using Bolt which is a pure Go key/value store. You can store session data in Bolt by using this store. This store implements the gorilla/sessions package's Store interface.

Based on Redistore codebase.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltStore

type BoltStore struct {
	Codecs  []securecookie.Codec
	Options *sessions.Options // default session configuration
	// contains filtered or unexported fields
}

boltstore stores sessions in a boltdb backend.

Example
store, err := NewStore(context.Background(), "example.db", Options{})
if err != nil {
	panic(err)
}
defer store.Close()
Output:

func NewStore

func NewStore(ctx context.Context, fn string, o Options) (*BoltStore, error)

func NewStoreWithDB

func NewStoreWithDB(ctx context.Context, db *bolt.DB, opts Options) (*BoltStore, error)

NewStoreWithDB returns a new BoltStore.

func (*BoltStore) Close

func (s *BoltStore) Close() error

func (*BoltStore) DB

func (s *BoltStore) DB() *bolt.DB

func (*BoltStore) Get

func (s *BoltStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See gorilla/sessions FilesystemStore.Get().

func (*BoltStore) New

func (s *BoltStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

See gorilla/sessions FilesystemStore.New().

func (*BoltStore) Save

func (s *BoltStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save adds a single session to the response.

type GobSerializer

type GobSerializer struct{}

GobSerializer uses gob package to encode the session map

func (GobSerializer) Deserialize

func (s GobSerializer) Deserialize(d []byte, ss *sessions.Session) error

Deserialize back to map[interface{}]interface{}

func (GobSerializer) Serialize

func (s GobSerializer) Serialize(ss *sessions.Session) ([]byte, error)

Serialize using gob

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer encode the session map to JSON.

func (JSONSerializer) Deserialize

func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) error

Deserialize back to map[string]interface{}

func (JSONSerializer) Serialize

func (s JSONSerializer) Serialize(ss *sessions.Session) ([]byte, error)

Serialize to JSON. Will err if there are unmarshalable key values

type Options

type Options struct {
	KeyPairs          [][]byte
	KeyPrefix         string
	BucketName        []byte
	SessionExpire     time.Duration // Amount of time for cookies/boltdb keys to expire.
	Serializer        SessionSerializer
	MaxLength         int // max length of session data (0 - unlimited with caution)
	ReapCheckInterval time.Duration
}

type SessionSerializer

type SessionSerializer interface {
	Deserialize(d []byte, ss *sessions.Session) error
	Serialize(ss *sessions.Session) ([]byte, error)
}

SessionSerializer provides an interface hook for alternative serializers

Jump to

Keyboard shortcuts

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