session

package
v0.0.0-...-b15094b Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSessionGCLifeTime  = 60      //second
	DefaultSessionMaxLifeTime = 20 * 60 //second
	DefaultSessionCookieName  = "dotweb_sessionId"
	DefaultSessionLength      = 20
	SessionMode_Runtime       = "runtime"
	SessionMode_Redis         = "redis"

	LogTarget_Session = "dotweb_session"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore Implement the SessionStore interface

func NewRedisStore

func NewRedisStore(config *StoreConfig) *RedisStore

create new redis store

func (*RedisStore) SessionCount

func (store *RedisStore) SessionCount() int

SessionAll get count number

func (*RedisStore) SessionExist

func (store *RedisStore) SessionExist(sessionId string) bool

SessionExist check session state exist by sessionId

func (*RedisStore) SessionGC

func (store *RedisStore) SessionGC() int

SessionGC clean expired session states in redis store,not use

func (*RedisStore) SessionRead

func (store *RedisStore) SessionRead(sessionId string) (*SessionState, error)

SessionRead get session state by sessionId

func (*RedisStore) SessionRemove

func (store *RedisStore) SessionRemove(sessionId string) error

SessionRemove delete session state in store

func (*RedisStore) SessionUpdate

func (store *RedisStore) SessionUpdate(state *SessionState) error

SessionUpdate update session state in store

type RuntimeStore

type RuntimeStore struct {
	// contains filtered or unexported fields
}

MemProvider Implement the provider interface

func NewRuntimeStore

func NewRuntimeStore(config *StoreConfig) *RuntimeStore

func (*RuntimeStore) SessionAccess

func (store *RuntimeStore) SessionAccess(sessionId string) error

SessionAccess expand time of session store by id in memory session

func (*RuntimeStore) SessionCount

func (store *RuntimeStore) SessionCount() int

SessionAll get count number of memory session

func (*RuntimeStore) SessionExist

func (store *RuntimeStore) SessionExist(sessionId string) bool

SessionExist check session state exist by sessionId

func (*RuntimeStore) SessionGC

func (store *RuntimeStore) SessionGC() int

SessionGC clean expired session stores in memory session

func (*RuntimeStore) SessionRead

func (store *RuntimeStore) SessionRead(sessionId string) (*SessionState, error)

SessionRead get session state by sessionId

func (*RuntimeStore) SessionRemove

func (store *RuntimeStore) SessionRemove(sessionId string) error

SessionRemove delete session state in store

func (*RuntimeStore) SessionUpdate

func (store *RuntimeStore) SessionUpdate(state *SessionState) error

SessionUpdate update session state in store

type SessionManager

type SessionManager struct {
	CookieName string `json:"cookieName"`
	GCLifetime int64  `json:"gclifetime"`
	// contains filtered or unexported fields
}

func NewDefaultSessionManager

func NewDefaultSessionManager(config *StoreConfig) (*SessionManager, error)

create new session manager with default config info

func NewSessionManager

func NewSessionManager(cookieName string, gcLifetime int64, config *StoreConfig) (*SessionManager, error)

create new seesion manager

func (*SessionManager) GC

func (manager *SessionManager) GC()

GC loop gc session data

func (*SessionManager) GetClientSessionID

func (manager *SessionManager) GetClientSessionID(req *http.Request) (string, error)

get session id from client default mode is from cookie

func (*SessionManager) GetSessionState

func (manager *SessionManager) GetSessionState(sessionId string) (session *SessionState, err error)

func (*SessionManager) NewSessionID

func (manager *SessionManager) NewSessionID() string

create new session id with DefaultSessionLength

type SessionState

type SessionState struct {
	// contains filtered or unexported fields
}

session state

func NewSessionState

func NewSessionState(store SessionStore, sessionId string, values map[interface{}]interface{}) *SessionState

func (*SessionState) Clear

func (state *SessionState) Clear() error

Clear clear all values in current store

func (*SessionState) Count

func (state *SessionState) Count() int

Count get all item's count in current state

func (*SessionState) Get

func (state *SessionState) Get(key interface{}) interface{}

Get get value by key in current state

func (*SessionState) GetInt

func (state *SessionState) GetInt(key interface{}) int

Get get value as int by key in current state

func (*SessionState) GetInt64

func (state *SessionState) GetInt64(key interface{}) int64

Get get value as int64 by key in current state

func (*SessionState) GetString

func (state *SessionState) GetString(key interface{}) string

Get get value as string by key in current state

func (*SessionState) Remove

func (state *SessionState) Remove(key interface{}) error

Remove remove value by key in current state

func (*SessionState) SessionID

func (state *SessionState) SessionID() string

SessionID get this id in current state

func (*SessionState) Set

func (state *SessionState) Set(key, value interface{}) error

Set set key-value to current state

type SessionStore

type SessionStore interface {
	SessionRead(sessionId string) (*SessionState, error)
	SessionExist(sessionId string) bool
	SessionUpdate(state *SessionState) error
	SessionRemove(sessionId string) error
	SessionCount() int //get all active session length
	SessionGC() int    //gc session and return out of date state num
}

func GetSessionStore

func GetSessionStore(config *StoreConfig) SessionStore

create new session store with store config

type StoreConfig

type StoreConfig struct {
	StoreName   string
	Maxlifetime int64
	ServerIP    string
}

session config info

func NewDefaultRedisConfig

func NewDefaultRedisConfig(serverIp string) *StoreConfig

create new store with default config and use redis store

func NewDefaultRuntimeConfig

func NewDefaultRuntimeConfig() *StoreConfig

create new store with default config and use runtime store

func NewStoreConfig

func NewStoreConfig(storeName string, maxlifetime int64, serverIp string) *StoreConfig

create new store config

Jump to

Keyboard shortcuts

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