Documentation ¶
Overview ¶
Package session is a default implementation of InterfaceSessionService and InterfaceSession declared in "github.com/ottemo/commerce/api" package
Package session is a default implementation of a application Session manager. That package provides "InterfaceSessionService" functionality declared in "github.com/ottemo/commerce/api" package.
Sessions are API call related storage. So, each call to API function supplied with own separated storage which can holds a values related to that particular action. By default sessions have a lifetime, within that period application routines can hold information fo future usage for either themselves or other API calls. In order to use previously created session API call should specify sessionID within application context.
Index ¶
- Constants
- Variables
- func GenerateSessionID() (string, error)
- type DefaultSession
- type DefaultSessionContainer
- func (it *DefaultSessionContainer) Get(key string) interface{}
- func (it *DefaultSessionContainer) GetID() string
- func (it *DefaultSessionContainer) GetUpdatedAt() time.Time
- func (it *DefaultSessionContainer) Set(key string, value interface{})
- func (it *DefaultSessionContainer) SetID(value string)
- func (it *DefaultSessionContainer) SetUpdatedAt(value time.Time)
- type DefaultSessionService
- func (it *DefaultSessionService) Close(sessionID string) error
- func (it *DefaultSessionService) FlushSession(sessionID string) error
- func (it *DefaultSessionService) GC() error
- func (it *DefaultSessionService) Get(sessionID string, create bool) (api.InterfaceSession, error)
- func (it *DefaultSessionService) GetKey(sessionID string, key string) interface{}
- func (it *DefaultSessionService) GetName() string
- func (it *DefaultSessionService) GetStorageName() string
- func (it *DefaultSessionService) IsEmpty(sessionID string) bool
- func (it *DefaultSessionService) LoadSession(sessionID string) (*DefaultSessionContainer, error)
- func (it *DefaultSessionService) New() (api.InterfaceSession, error)
- func (it *DefaultSessionService) SetKey(sessionID string, key string, value interface{})
- func (it *DefaultSessionService) Touch(sessionID string) error
- type FilesystemSessionService
- type InterfaceServiceStorage
Constants ¶
const ( ConstSessionLifeTime = 26280000 // session idle period before expire (in sec); set to 365 days ConstSessionUpdateTime = 10 // '0' - immediate mode, '>0' - update timer mode (in sec) ConstSessionKeepInMemoryItems = 1000 // limits application sessions array for "immediate mode", '0' - unlimited ConstErrorModule = "api/session" ConstErrorLevel = env.ConstErrorLevelService ConstStorageFolder = "./var/session/" ConstCryptSession = false )
Package global constants
Variables ¶
var (
SessionService api.InterfaceSessionService
)
Package global variables
Functions ¶
func GenerateSessionID ¶
GenerateSessionID returns new session id number
Types ¶
type DefaultSession ¶
type DefaultSession string
DefaultSession is a default implementer of InterfaceSession declared in "github.com/ottemo/commerce/api" package
func (DefaultSession) Close ¶
func (it DefaultSession) Close() error
Close makes current session instance expired
func (DefaultSession) Get ¶
func (it DefaultSession) Get(key string) interface{}
Get returns session value by a given key or nil - if not set
func (DefaultSession) GetID ¶
func (it DefaultSession) GetID() string
GetID returns current session id
func (DefaultSession) IsEmpty ¶
func (it DefaultSession) IsEmpty() bool
IsEmpty checks if session contains data
func (DefaultSession) Set ¶
func (it DefaultSession) Set(key string, value interface{})
Set assigns value to session key
func (DefaultSession) Touch ¶
func (it DefaultSession) Touch() error
Touch updates session last modification time to current moment
type DefaultSessionContainer ¶
type DefaultSessionContainer struct { Data map[string]interface{} UpdatedAt time.Time // contains filtered or unexported fields }
DefaultSessionContainer is a structure to hold session related information
func (*DefaultSessionContainer) Get ¶
func (it *DefaultSessionContainer) Get(key string) interface{}
func (*DefaultSessionContainer) GetID ¶
func (it *DefaultSessionContainer) GetID() string
func (*DefaultSessionContainer) GetUpdatedAt ¶
func (it *DefaultSessionContainer) GetUpdatedAt() time.Time
func (*DefaultSessionContainer) Set ¶
func (it *DefaultSessionContainer) Set(key string, value interface{})
func (*DefaultSessionContainer) SetID ¶
func (it *DefaultSessionContainer) SetID(value string)
func (*DefaultSessionContainer) SetUpdatedAt ¶
func (it *DefaultSessionContainer) SetUpdatedAt(value time.Time)
type DefaultSessionService ¶
type DefaultSessionService struct {
// contains filtered or unexported fields
}
DefaultSessionService is a basic implementer of InterfaceSessionService declared in "github.com/ottemo/commerce/api" package
func InitDefaultSessionService ¶
func InitDefaultSessionService() *DefaultSessionService
InitDefaultSessionService makes a new instance of DefaultSessionService
- makes internal fields initialization
func (*DefaultSessionService) Close ¶
func (it *DefaultSessionService) Close(sessionID string) error
Close makes current session instance expired
func (*DefaultSessionService) FlushSession ¶
func (it *DefaultSessionService) FlushSession(sessionID string) error
FlushSession is a stub function for no action
func (*DefaultSessionService) GC ¶
func (it *DefaultSessionService) GC() error
GC is a garbage collector for sessions, it removes expired sessions, flushes to storage, etc.
func (*DefaultSessionService) Get ¶
func (it *DefaultSessionService) Get(sessionID string, create bool) (api.InterfaceSession, error)
Get returns session object for given session id or nil of not currently exists
func (*DefaultSessionService) GetKey ¶
func (it *DefaultSessionService) GetKey(sessionID string, key string) interface{}
GetKey returns session value for a given key or nil - if not set
func (*DefaultSessionService) GetName ¶
func (it *DefaultSessionService) GetName() string
GetName returns implementation name of session service
func (*DefaultSessionService) GetStorageName ¶
func (it *DefaultSessionService) GetStorageName() string
GetStorageName returns storage implementation name for a session service
func (*DefaultSessionService) IsEmpty ¶
func (it *DefaultSessionService) IsEmpty(sessionID string) bool
IsEmpty checks if session contains data
func (*DefaultSessionService) LoadSession ¶
func (it *DefaultSessionService) LoadSession(sessionID string) (*DefaultSessionContainer, error)
LoadSession is a stub function for no action
func (*DefaultSessionService) New ¶
func (it *DefaultSessionService) New() (api.InterfaceSession, error)
New initializes new session instance
func (*DefaultSessionService) SetKey ¶
func (it *DefaultSessionService) SetKey(sessionID string, key string, value interface{})
SetKey assigns value to session key
func (*DefaultSessionService) Touch ¶
func (it *DefaultSessionService) Touch(sessionID string) error
Touch updates session last modification time to current moment
type FilesystemSessionService ¶
type FilesystemSessionService struct {
*DefaultSessionService
}
FilesystemSessionService is a filesystem based storage implementer based on "DefaultSessionService"
func (*FilesystemSessionService) FlushSession ¶
func (it *FilesystemSessionService) FlushSession(sessionID string) error
FlushSession serializes session into filesystem storage
- routine not checks session expiration or modification time - it just flushes data to storage
func (*FilesystemSessionService) GetStorageName ¶
func (it *FilesystemSessionService) GetStorageName() string
GetStorageName returns storage implementation name for a session service
func (*FilesystemSessionService) LoadSession ¶
func (it *FilesystemSessionService) LoadSession(sessionID string) (*DefaultSessionContainer, error)
LoadSession de-serializes file from filesystem storage, returns nil on error
type InterfaceServiceStorage ¶
type InterfaceServiceStorage interface { GetStorageName() string LoadSession(sessionID string) (*DefaultSessionContainer, error) FlushSession(sessionID string) error }
InterfaceServiceStorage session storage layer for a session service