Documentation
¶
Overview ¶
Package session provides easy-to-use, secure HTTP session management.
Index ¶
- func Add(sess *Session, w http.ResponseWriter)
- func Close()
- func Init(o Options)
- func Len() int
- func Reinit()
- func Remove(sess *Session, w http.ResponseWriter)
- func SetMaxSessions(n int)
- type Options
- type SessOptions
- type Session
- func (s *Session) Accessed() time.Time
- func (s *Session) Attr(name string) interface{}
- func (s *Session) Attrs() map[string]interface{}
- func (s *Session) Created() time.Time
- func (s *Session) ID() string
- func (s *Session) SetAttr(name string, value interface{})
- func (s *Session) Timeout() time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add(sess *Session, w http.ResponseWriter)
Add stores sess and sets the session cookie on w.
func Init ¶
func Init(o Options)
Init closes the current global manager and replaces it with a new one configured by o. Use this at startup or in tests to override defaults.
Init discards every stored session. Call it once, at startup: it is not a way to reconfigure a running server.
func Remove ¶
func Remove(sess *Session, w http.ResponseWriter)
Remove deletes sess and instructs the client to clear its cookie.
func SetMaxSessions ¶ added in v1.1.0
func SetMaxSessions(n int)
SetMaxSessions changes the global manager's session cap. 0 means unlimited.
Types ¶
type Options ¶
type Options struct {
// Name of the session ID cookie. Default: "sessid".
CookieName string
// Allow session cookies over plain HTTP. Default: false (HTTPS only).
AllowHTTP bool
// Max age of the session cookie. Default: 30 days.
// Set to a negative value for a session-scoped cookie (expires when browser closes).
CookieMaxAge time.Duration
// Cookie path. Default: "/".
CookiePath string
// How often the store is checked for expired sessions. Default: 10s.
CleanInterval time.Duration
// Maximum number of stored sessions. 0 means unlimited. When the store is
// full, Add evicts the least recently accessed sessions to make room, so
// adding a session never fails.
MaxSessions int
}
Options configures the session manager. All fields are optional.
type SessOptions ¶
type SessOptions struct {
// Initial attributes stored in the session.
Attrs map[string]interface{}
// Session timeout. Default: 30 minutes.
Timeout time.Duration
}
SessOptions defines options for NewSession. All fields are optional.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds the data for a single HTTP session. All methods are safe for concurrent use.
func NewSession ¶
func NewSession(o ...SessOptions) *Session
NewSession creates a new Session. Pass a SessOptions value to override defaults.