session

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// The key for the identity of the session.
	SessionIDKey = "_ID"
	// The expiration date of the session.
	TimestampKey = "_TS"
	// The value name indicating how long the session should persist - ie should it persist after the browser closes
	// this is set under the TimestampKey if the session data should expire immediately.
	SessionValueName = "session"
	// The key container for the json objects of the data, any non strings found in the map will be placed in here
	// serialized by key using JSON.
	SessionObjectKeyName = "_object_"
	// The mapped session object.
	SessionMapKeyName = "_map_"
	// The suffix of the session cookie.
	SessionCookieSuffix = "_SESSION"
)

Variables

View Source
var SESSION_VALUE_NOT_FOUND = errors.New("Session value not found")

Constant error if session value is not found.

Functions

func InitSession

func InitSession(coreLogger logger.MultiLogger)

Types

type Session

type Session map[string]interface{}

Session data, can be any data, there are reserved keywords used by the storage data SessionIDKey Is the key name for the session TimestampKey Is the time that the session should expire

func NewSession

func NewSession() Session

func (Session) Del

func (s Session) Del(key string)

Delete the key from the sessionObjects and Session.

func (Session) Empty

func (s Session) Empty() bool

Checks to see if the session is empty.

func (Session) Get

func (s Session) Get(key string) (newValue interface{}, err error)

Get an object or property from the session it may be embedded inside the session.

func (Session) GetDefault

func (s Session) GetDefault(key string, value interface{}, defaultValue interface{}) interface{}

Returns the default value if the key is not found.

func (Session) GetExpiration

func (s Session) GetExpiration(expireAfterDuration time.Duration) time.Time

getExpiration return a time.Time with the session's expiration date. It uses the passed in expireAfterDuration to add with the current time if the timeout is not browser dependent (ie session). If previous session has set to "session", the time returned is time.IsZero().

func (Session) GetInto

func (s Session) GetInto(key string, target interface{}, force bool) (result interface{}, err error)

Get into the specified value. If value exists in the session it will just return the value.

func (Session) GetProperty

func (s Session) GetProperty(key string, value interface{}) (interface{}, error)

Extract the values from the session.

func (Session) ID

func (s Session) ID() string

ID retrieves from the cookie or creates a time-based UUID identifying this session.

func (Session) Load

func (s Session) Load(data map[string]string)

Set the session object from the loaded data.

func (Session) Serialize

func (s Session) Serialize() map[string]string

Convert the map to a simple map[string]string map this will marshal any non string objects encountered and store them the the jsonMap The expiration time will also be assigned.

func (Session) SessionTimeoutExpiredOrMissing

func (s Session) SessionTimeoutExpiredOrMissing() bool

sessionTimeoutExpiredOrMissing returns a boolean of whether the session cookie is either not present or present but beyond its time to live; i.e., whether there is not a valid session.

func (Session) Set

func (s Session) Set(key string, value interface{}) error

Places the object into the session, a nil value will cause remove the key from the session (or you can use the Session.Del(key) function.

func (Session) SetDefaultExpiration

func (s Session) SetDefaultExpiration()

SetDefaultExpiration sets session to expire after default duration.

func (Session) SetNoExpiration

func (s Session) SetNoExpiration()

SetNoExpiration sets session to expire when browser session ends.

Jump to

Keyboard shortcuts

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