session

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2019 License: MIT Imports: 13 Imported by: 15

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"
)
View Source
const (
	HystrixErrorCount = 20
)

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, error)

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 {
	GCLifetime int64 `json:"gclifetime"`
	// contains filtered or unexported fields
}

func NewDefaultSessionManager

func NewDefaultSessionManager(appLog logger.AppLog, config *StoreConfig) (*SessionManager, error)

NewDefaultSessionManager create new session manager with default config info

func NewSessionManager

func NewSessionManager(gcLifetime int64, appLog logger.AppLog, config *StoreConfig) (*SessionManager, error)

NewSessionManager 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)

GetClientSessionID 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

NewSessionID create new session id with DefaultSessionLength

func (*SessionManager) StoreConfig

func (manager *SessionManager) StoreConfig() *StoreConfig

StoreConfig return store config

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

GetSessionStore create new session store with store config

type StoreConfig

type StoreConfig struct {
	StoreName       string
	Maxlifetime     int64  // session life time, with second
	CookieName      string // custom cookie name which sessionid store
	ServerIP        string // if use redis, connection string, like "redis://:password@10.0.1.11:6379/0"
	BackupServerUrl string // if use redis, if ServerIP is down, use this server, like "redis://:password@10.0.1.11:6379/0"
	StoreKeyPre     string // if use redis, set custom redis key-pre; default is dotweb:session:
}

session config info

func NewDefaultRedisConfig

func NewDefaultRedisConfig(serverIp string) *StoreConfig

NewDefaultRedisConfig create new store with default config and use redis store

func NewDefaultRuntimeConfig

func NewDefaultRuntimeConfig() *StoreConfig

NewDefaultRuntimeConfig create new store with default config and use runtime store

func NewRedisConfig

func NewRedisConfig(serverIp string, storeKeyPre string) *StoreConfig

NewRedisConfig create new store with config and use redis store must set serverIp and storeKeyPre

func NewStoreConfig

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

NewStoreConfig create new store config

Jump to

Keyboard shortcuts

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