Documentation ¶
Index ¶
- Variables
- type Database
- func (db *Database) Acquire(sid string, expires time.Duration) sessions.LifeTime
- func (db *Database) Clear(sid string) error
- func (db *Database) Close() error
- func (db *Database) Decode(sid, key string, outPtr interface{}) error
- func (db *Database) Delete(sid string, key string) (deleted bool)
- func (db *Database) Get(sid string, key string) (value interface{})
- func (db *Database) Len(sid string) (n int)
- func (db *Database) OnUpdateExpiration(sid string, newExpires time.Duration) error
- func (db *Database) Release(sid string) error
- func (db *Database) Set(sid string, key string, value interface{}, ttl time.Duration, immutable bool) error
- func (db *Database) SetLogger(logger *golog.Logger)
- func (db *Database) Visit(sid string, cb func(key string, value interface{})) error
Constants ¶
This section is empty.
Variables ¶
var (
DefaultFileMode = 0755
)
DefaultFileMode used as the default database's "fileMode" for creating the sessions directory path, opening and write the session file.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct { // Service is the underline badger database connection, // it's initialized at `New` or `NewFromDB`. // Can be used to get stats. Service *badger.DB // contains filtered or unexported fields }
Database the badger(key-value file-based) session storage.
func New ¶
New creates and returns a new badger(key-value file-based) storage instance based on the "directoryPath". DirectoryPath should is the directory which the badger database will store the sessions, i.e ./sessions
It will remove any old session files.
func NewFromDB ¶
func NewFromDB(service *badger.DB) *Database
NewFromDB same as `New` but accepts an already-created custom badger connection instead.
func (*Database) Acquire ¶
Acquire receives a session's lifetime from the database, if the return value is LifeTime{} then the session manager sets the life time based on the expiration duration lives in configuration.
func (*Database) Decode ¶ added in v12.2.0
Decode binds the "outPtr" to the value associated to the provided "key".
func (*Database) OnUpdateExpiration ¶
OnUpdateExpiration not implemented here, yet. Note that this error will not be logged, callers should catch it manually.
func (*Database) Release ¶
Release destroys the session, it clears and removes the session entry, session manager will create a new session ID on the next request after this call.
func (*Database) Set ¶
func (db *Database) Set(sid string, key string, value interface{}, ttl time.Duration, immutable bool) error
Set sets a key value of a specific session. Ignore the "immutable".