Documentation ¶
Index ¶
Constants ¶
View Source
const ( // SessionCookieName key of SessionID store in Cookie SessionCookieName = "session_id" // SessionName key of session in gin.context SessionContextName = "session" )
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware() gin.HandlerFunc
AuthMiddleware 认证中间件 从请求的session Data中获取isLogin
func NewRedisSessionMgr ¶
func NewRedisSessionMgr() *redisSessionMgr
NewRedisSessionMgr redis-based sessionMgr constructor
func SessionMiddleware ¶
func SessionMiddleware(sm SessionMgr, options Options) gin.HandlerFunc
SessionMiddleware gin middleware
Types ¶
type MemSessionMgr ¶
type MemSessionMgr struct {
// contains filtered or unexported fields
}
MemSessionMgr a memory-based manager
func (*MemSessionMgr) Clear ¶
func (m *MemSessionMgr) Clear(sessionID string)
Clear delete the request session in sessionMgr
func (*MemSessionMgr) CreateSession ¶
func (m *MemSessionMgr) CreateSession() (sd Session)
CreateSession create a new session
func (*MemSessionMgr) GetSession ¶
func (m *MemSessionMgr) GetSession(sessionID string) (sd Session, err error)
GetSession get the session by sessionID
type Options ¶
type Options struct { Path string Domain string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int Secure bool HttpOnly bool }
Options Cookie Options
type Session ¶
type Session interface { ID() string Load() error // load Get(string) (interface{}, error) Set(string, interface{}) Del(string) Save() SetExpired(int) }
Session stores values for a session
type SessionMgr ¶
type SessionMgr interface { Init(addr string, options ...string) error // init the session store GetSession(string) (Session, error) // get the session by sessionID CreateSession() Session // create a new session Clear(string) // clear the request session data }
SessionMgr a session manager
func CreateSessionMgr ¶
func CreateSessionMgr(name string, addr string, options ...string) (sm SessionMgr, err error)
CreateSessionMgr create a sessionMgr by given name
Click to show internal directories.
Click to hide internal directories.