store

package
v0.0.0-...-d8a5e5d Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPath   = "/"
	DefaultMaxAge = 60 * 60 * 24 * 30 // 30days
)

Defaults for sessions.Options

View Source
const (
	DefaultBatchSize     = 100
	DefaultCheckInterval = time.Minute
)

Defaults for reaper.Options

View Source
const (
	DefaultBucketName = "sessions"
)

Defaults for store.Options

Variables

This section is empty.

Functions

func Checker

func Checker(store *Store)

Checker invokes all possible goroutines.

func CloseAndFree

func CloseAndFree(store *Store)

func Expired

func Expired(session Session) bool

Expired checks if the session is expired.

func Quit

func Quit(quitC chan<- struct{}, doneC <-chan struct{})

Quit terminates the reap goroutine.

func Run

func Run(db *bbolt.DB, options ROptions) (chan<- struct{}, <-chan struct{})

Run invokes a reap function as a goroutine.

Types

type Config

type Config struct {
	// SessionOptions represents options for a session.
	SessionOptions sessions.Options
	// DBOptions represents options for a database.
	DBOptions Options
	// ReaperOptions represents options for a reaper routine
	ReaperOptions ROptions
}

Config represents a config for a session store.

func NewDefaultConfig

func NewDefaultConfig() *Config

type Options

type Options struct {
	// BucketName represents the name of the bucket which contains sessions.
	BucketName []byte
	// If FreeDB is true, then after closing DB and store, DB will be deleted.
	FreeDB bool
}

Options represents options for a database.

type ROptions

type ROptions struct {
	//StartRoutine represents the status of reaper
	StartRoutine bool
	// BucketName represents the name of the bucket which contains sessions.
	BucketName []byte
	// BatchSize represents the maximum number of sessions which the reaper
	// process at one time.
	BatchSize int
	// CheckInterval represents the interval between the reaper's invocation.
	CheckInterval time.Duration
}

type Session

type Session struct {
	Values           []byte `json:"Values"`
	ExpiresAt        int64  `json:"ExpiresAt"`
	XXX_unrecognized []byte `json:"-"`
}

func GetSession

func GetSession(data []byte) (Session, error)

Session converts the byte slice to the session struct value.

func NewSession

func NewSession(values []byte, maxAge int) *Session

NewSession creates and returns a session data.

func (*Session) GetExpiresAt

func (m *Session) GetExpiresAt() int64

func (*Session) GetValues

func (m *Session) GetValues() []byte

func (*Session) ProtoMessage

func (*Session) ProtoMessage()

func (*Session) Reset

func (m *Session) Reset()

func (*Session) String

func (m *Session) String() string

type Store

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

Store represents a session store.

func NewStore

func NewStore(db *bbolt.DB, config Config, keyPairs ...[]byte) (*Store, error)

Creates new sesion storage using opened db.

func NewStoreWithDB

func NewStoreWithDB(dbPath string, config Config, keyPairs ...[]byte) (*Store, error)

Opens a db and creates new sesion storage.

func (*Store) Get

func (s *Store) 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 (*Store) New

func (s *Store) 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 (*Store) Save

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

Save adds a single session to the response.

Jump to

Keyboard shortcuts

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