session

package
v0.0.0-...-de73072 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: GPL-3.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Md5

func Md5(text string) string

Md5 caculate the md5 of string use to generate id

func Open

func Open()

Open session server

Types

type IO

type IO interface {
	Manager
	Reader
	Writer
}

IO Interface

func Auto

func Auto(res http.ResponseWriter, req *http.Request) (session IO, NewSession bool)

Auto will check-get session or create new one, try to find sessionID in req cookie if no vaild session it will create a new session,and reurn second value as true in addition this func will add cookie

func Get

func Get(sessionID string, req *http.Request) IO

Get and check session

func GetByCookie

func GetByCookie(req *http.Request) IO

GetByCookie get session by cookie

func New

func New(req *http.Request) IO

New session

type Manager

type Manager interface {
	ExpireTime(expireTime time.Duration) time.Duration
	Belong(*http.Request) bool
	ExtraInfo(address, userAgent string) (string, string)
	RLock()
	RUnlock()
	Lock()
	Unlock()
	Expired() bool
	ID() string
	// contains filtered or unexported methods
}

Manager Interface

type Reader

type Reader interface {
	Get(key string) (string, bool)
	GetInt(key string) (int, bool)
	GetTime(key string) (time.Time, bool)
	Have(key string) bool
}

Reader Interface

type Session

type Session struct {
	Map map[string]*sessionObj
	// contains filtered or unexported fields
}

Session struct

func (*Session) Belong

func (session *Session) Belong(req *http.Request) bool

Belong check wether req match the requirement of session

func (*Session) Delete

func (session *Session) Delete(key string)

Delete key, delete will not cause panic

func (*Session) ExpireTime

func (session *Session) ExpireTime(expireTime time.Duration) time.Duration

ExpireTime set the ExpireTime of session and retuen ExpireTime of session, ExpireTime smaller than 0 will not change ExpireTime of session so than can be use to get ExpireTime

func (*Session) Expired

func (session *Session) Expired() bool

Expired return wether session is expired

func (*Session) ExtraInfo

func (session *Session) ExtraInfo(address, userAgent string) (string, string)

ExtraInfo set ExtraInfo for auth, set "" will not change, can use to get ExtraInfo

func (*Session) Get

func (session *Session) Get(key string) (res string, ok bool)

Get return type is string if not have key or value type is not string return ""

func (*Session) GetInt

func (session *Session) GetInt(key string) (res int, ok bool)

GetInt return type is int

func (*Session) GetTime

func (session *Session) GetTime(key string) (res time.Time, ok bool)

GetTime return type is time.Time

func (*Session) Have

func (session *Session) Have(key string) bool

Have if session have key return true

func (*Session) ID

func (session *Session) ID() string

ID return sessionID

func (*Session) Lock

func (session *Session) Lock()

Lock Lock

func (*Session) Put

func (session *Session) Put(key string, value string, expireTime time.Duration)

Put string set expireTime=0 to enable infinit lifetime

func (*Session) PutInt

func (session *Session) PutInt(key string, value int, expireTime time.Duration)

PutInt int set expireTime=0 to enable infinit lifetime

func (*Session) PutTime

func (session *Session) PutTime(key string, value time.Time, expireTime time.Duration)

PutTime time.Time set expireTime=0 to enable infinit lifetime

func (*Session) RLock

func (session *Session) RLock()

RLock RLock

func (*Session) RUnlock

func (session *Session) RUnlock()

RUnlock RUnlock

func (*Session) Unlock

func (session *Session) Unlock()

Unlock Unlock

type Writer

type Writer interface {
	Put(key, value string, expireTime time.Duration)
	PutInt(key string, value int, expireTime time.Duration)
	PutTime(key string, value time.Time, expireTime time.Duration)
	Delete(key string)
}

Writer Interface

Jump to

Keyboard shortcuts

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