Documentation ¶
Index ¶
- type FromMemory
- type Session
- type SessionFromMemory
- type SessionManager
- func (m *SessionManager) BeginSession(w http.ResponseWriter, r *http.Request) Session
- func (m *SessionManager) CookieIsExists(r *http.Request) bool
- func (m *SessionManager) Destroy(w http.ResponseWriter, r *http.Request)
- func (m *SessionManager) GC()
- func (m *SessionManager) GetCookieN() string
- func (m *SessionManager) GetSessionById(sid string) Session
- func (m *SessionManager) In(i []byte)
- func (m *SessionManager) Out() []byte
- func (m *SessionManager) SetMaxAge(t int64)
- func (m *SessionManager) SetSessionFrom(storage Storage)
- func (m *SessionManager) Update(w http.ResponseWriter, r *http.Request)
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FromMemory ¶
session来自内存
func (*FromMemory) DestroySession ¶
func (fm *FromMemory) DestroySession(Sid string) error
func (*FromMemory) GCSession ¶
func (fm *FromMemory) GCSession()
func (*FromMemory) GetSession ¶
func (fm *FromMemory) GetSession(Sid string) Session
func (*FromMemory) In ¶
func (m *FromMemory) In(i []byte)
func (*FromMemory) InitSession ¶
func (fm *FromMemory) InitSession(Sid string, MaxAge int64) (Session, error)
func (*FromMemory) Out ¶
func (m *FromMemory) Out() []byte
type Session ¶
type Session interface { Set(key, value interface{}) Get(key interface{}) interface{} Remove(key interface{}) error GetId() string Update() }
-------------session_implements----------------- Session操作接口,不同存储方式的Sesion操作不同,实现也不同
type SessionFromMemory ¶
type SessionFromMemory struct { Sid string LastAccessedTime time.Time MaxAge int64 Data map[interface{}]interface{} // contains filtered or unexported fields }
session实现
func (*SessionFromMemory) Get ¶
func (si *SessionFromMemory) Get(key interface{}) interface{}
func (*SessionFromMemory) GetId ¶
func (si *SessionFromMemory) GetId() string
func (*SessionFromMemory) Remove ¶
func (si *SessionFromMemory) Remove(key interface{}) error
func (*SessionFromMemory) Set ¶
func (si *SessionFromMemory) Set(key, value interface{})
func (*SessionFromMemory) Update ¶
func (si *SessionFromMemory) Update()
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
--------------session_manager---------------------- 管理Session,实际操作cookie,Storage 由于该结构体是整个应用级别的,写、修改都需要枷锁
func (*SessionManager) BeginSession ¶
func (m *SessionManager) BeginSession(w http.ResponseWriter, r *http.Request) Session
先判断当前请求的cookie中是否存在有效的session,存在返回,不存在创建
func (*SessionManager) CookieIsExists ¶
func (m *SessionManager) CookieIsExists(r *http.Request) bool
func (*SessionManager) Destroy ¶
func (m *SessionManager) Destroy(w http.ResponseWriter, r *http.Request)
手动销毁session,同时删除cookie
func (*SessionManager) GC ¶
func (m *SessionManager) GC()
func (*SessionManager) GetCookieN ¶
func (m *SessionManager) GetCookieN() string
func (*SessionManager) GetSessionById ¶
func (m *SessionManager) GetSessionById(sid string) Session
通过ID获取session
func (*SessionManager) In ¶
func (m *SessionManager) In(i []byte)
func (*SessionManager) Out ¶
func (m *SessionManager) Out() []byte
func (*SessionManager) SetMaxAge ¶
func (m *SessionManager) SetMaxAge(t int64)
func (*SessionManager) SetSessionFrom ¶
func (m *SessionManager) SetSessionFrom(storage Storage)
func (*SessionManager) Update ¶
func (m *SessionManager) Update(w http.ResponseWriter, r *http.Request)
更新超时
type Storage ¶
type Storage interface { //初始化一个session,id根据需要生成后传入 InitSession(sid string, maxAge int64) (Session, error) //根据sid,获得当前session GetSession(sid string) Session //销毁session DestroySession(sid string) error //回收 GCSession() In([]byte) Out() []byte }
--------------session_from--------------------------- session存储方式接口,可以存储在内存,数据库或者文件 分别实现该接口即可 如存入数据库的CRUD操作
Click to show internal directories.
Click to hide internal directories.