Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateSessionID(sid string) error
- type Conf
- type CookieConf
- type CtxKey
- type SameSite
- type Service
- type Session
- func (s *Session) AddAttribute(k CtxKey, v interface{})
- func (s *Session) GetAttribute(k CtxKey) (interface{}, bool)
- func (s *Session) IsExpired() bool
- func (s *Session) WithAttributes(attrs map[CtxKey]interface{})
- func (s *Session) WithCookieConf(cc CookieConf)
- func (s *Session) WithSessionConf(sc Conf)
- func (s *Session) WithUserID(uid string)
- type Store
Constants ¶
const ( LogKeySID = "session.sid" LogKeyRQID = "session.rqud" LogKeyDebugError = "session.dbg_error" )
Variables ¶
var ErrSessionNotFound = errors.New("sessionservice: session not found")
Functions ¶
func ValidateSessionID ¶
ValidateSessionID validate session id format
Types ¶
type Conf ¶
Conf contains session parameters
func DefaultSessionConf ¶
func DefaultSessionConf() Conf
type CookieConf ¶
type CookieConf struct { Path string Domain string Secure bool HTTPOnly bool MaxAge int SameSite SameSite }
CookieConf contains cookie parameters
func DefaultCookieConf ¶
func DefaultCookieConf() CookieConf
type Service ¶
type Service interface { CreateAnonymSession(ctx context.Context, cc CookieConf, sc Conf, keyAndValues ...interface{}) (*Session, error) CreateUserSession(ctx context.Context, uid string, cc CookieConf, sc Conf, keyAndValues ...interface{}) (*Session, error) LoadSession(ctx context.Context, sid string) (*Session, error) InvalidateSession(ctx context.Context, sid string) error AddAttributes(ctx context.Context, sid string, keyAndValues ...interface{}) (*Session, error) RemoveAttributes(ctx context.Context, sid string, keys ...CtxKey) (*Session, error) }
func NewService ¶
NewService Create implementation of Service to work with session
logr.Logger may be useful only for debugging purposes, Nnone of errors will be logged as logr.Error. It's up to service that call these methods to decide what is really error in terms of application and what is not.
reqIDKey is key to extract request id from the context
type Session ¶
type Session struct { ID string Data map[CtxKey]interface{} Opts CookieConf Anonym bool Active bool UID string IdleTimeout time.Duration AbsTimeout time.Duration LastAccessedAt time.Time CreatedAt time.Time }
Session is representation of session in terms of current module. Data - should be used to store any data within a session.
IdleTimeout and LastAccessedAt will be used to expire session based on user activity within the session.
AbsTimeout and CreatedAt will be used to expire session based on full session lifetime.
UID is supposed to store user identity who session belongs to.
Anonym is supposed to use during authentication process.
func NewSession ¶
NewSession return new session with default configuration IdleTimeout = 24h AbsTimeout = 7d Anonym = true Active = true Opts: Secure, HTTPOnly, Strict
func (*Session) AddAttribute ¶
AddAttribute add a new attribute to the session
func (*Session) GetAttribute ¶
GetAttribute return a value from the session It return nill and false if attribute doesn't exists
func (*Session) WithAttributes ¶ added in v0.1.2
func (*Session) WithCookieConf ¶
func (s *Session) WithCookieConf(cc CookieConf)
WithCookieConf add cookie to the session
func (*Session) WithSessionConf ¶
WithSessionConf configure session timeouts
func (*Session) WithUserID ¶
WithUserID add user identity to the session
type Store ¶
type Store interface { // Save store session and return its updated copy Save(ctx context.Context, s *Session) (*Session, error) // Save session attributes and return updated copy of session AddAttributes(ctx context.Context, sid string, data map[CtxKey]interface{}) (*Session, error) // Remove session attributes and return updated copy of session RemoveAttributes(ctx context.Context, sid string, keys ...CtxKey) (*Session, error) // Load session by its id Load(ctx context.Context, sid string) (*Session, error) // Invalidate session by its id Invalidate(ctx context.Context, sid string) error }