mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
add two new examples and share the app's specific logger instance with sessions databases and APIBuilder
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12/core/memstore"
|
||||
|
||||
"github.com/kataras/golog"
|
||||
)
|
||||
|
||||
// ErrNotImplemented is returned when a particular feature is not yet implemented yet.
|
||||
@@ -22,6 +24,8 @@ var ErrNotImplemented = errors.New("not implemented yet")
|
||||
//
|
||||
// Look the `sessiondb` folder for databases implementations.
|
||||
type Database interface {
|
||||
// SetLogger should inject a logger to this Database.
|
||||
SetLogger(*golog.Logger)
|
||||
// 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.
|
||||
Acquire(sid string, expires time.Duration) LifeTime
|
||||
@@ -36,7 +40,7 @@ type Database interface {
|
||||
OnUpdateExpiration(sid string, newExpires time.Duration) error
|
||||
// Set sets a key value of a specific session.
|
||||
// The "immutable" input argument depends on the store, it may not implement it at all.
|
||||
Set(sid string, lifetime LifeTime, key string, value interface{}, immutable bool)
|
||||
Set(sid string, lifetime *LifeTime, key string, value interface{}, immutable bool)
|
||||
// Get retrieves a session value based on the key.
|
||||
Get(sid string, key string) interface{}
|
||||
// Visit loops through all session keys and values.
|
||||
@@ -61,6 +65,8 @@ var _ Database = (*mem)(nil)
|
||||
|
||||
func newMemDB() Database { return &mem{values: make(map[string]*memstore.Store)} }
|
||||
|
||||
func (s *mem) SetLogger(*golog.Logger) {}
|
||||
|
||||
func (s *mem) Acquire(sid string, expires time.Duration) LifeTime {
|
||||
s.mu.Lock()
|
||||
s.values[sid] = new(memstore.Store)
|
||||
@@ -72,7 +78,7 @@ func (s *mem) Acquire(sid string, expires time.Duration) LifeTime {
|
||||
func (s *mem) OnUpdateExpiration(string, time.Duration) error { return nil }
|
||||
|
||||
// immutable depends on the store, it may not implement it at all.
|
||||
func (s *mem) Set(sid string, lifetime LifeTime, key string, value interface{}, immutable bool) {
|
||||
func (s *mem) Set(sid string, lifetime *LifeTime, key string, value interface{}, immutable bool) {
|
||||
s.mu.RLock()
|
||||
s.values[sid].Save(key, value, immutable)
|
||||
s.mu.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user