Documentation ¶
Overview ¶
Package session a middleware that provides the session management of Macaron.
Index ¶
- func DecodeGob(encoded []byte) (out map[interface{}]interface{}, err error)
- func EncodeGob(obj map[interface{}]interface{}) ([]byte, error)
- func GetCookie(req *http.Request, name string) string
- func Register(name string, provider Provider)
- func RegisterFn(name string, providerfn func() Provider)
- func Sessioner(options ...Options) func(next http.Handler) http.Handler
- type FileProvider
- func (p *FileProvider) Count() int
- func (p *FileProvider) Destroy(sid string) error
- func (p *FileProvider) Exist(sid string) bool
- func (p *FileProvider) GC()
- func (p *FileProvider) Init(maxlifetime int64, rootPath string) error
- func (p *FileProvider) Read(sid string) (_ RawStore, err error)
- func (p *FileProvider) Regenerate(oldsid, sid string) (_ RawStore, err error)
- type FileStore
- type Manager
- func (m *Manager) Count() int
- func (m *Manager) Destroy(resp http.ResponseWriter, req *http.Request) error
- func (m *Manager) GC()
- func (m *Manager) Read(sid string) (RawStore, error)
- func (m *Manager) RegenerateID(resp http.ResponseWriter, req *http.Request) (sess RawStore, err error)
- func (m *Manager) SetSecure(secure bool)
- func (m *Manager) Start(resp http.ResponseWriter, req *http.Request) (RawStore, error)
- type MemProvider
- func (p *MemProvider) Count() int
- func (p *MemProvider) Destroy(sid string) error
- func (p *MemProvider) Exist(sid string) bool
- func (p *MemProvider) GC()
- func (p *MemProvider) Init(maxLifetime int64, _ string) error
- func (p *MemProvider) Read(sid string) (_ RawStore, err error)
- func (p *MemProvider) Regenerate(oldsid, sid string) (RawStore, error)
- type MemStore
- type Options
- type Provider
- type RawStore
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFn ¶
RegisterFn registers a provider function.
Types ¶
type FileProvider ¶
type FileProvider struct {
// contains filtered or unexported fields
}
FileProvider represents a file session provider implementation.
func (*FileProvider) Count ¶
func (p *FileProvider) Count() int
Count counts and returns number of sessions.
func (*FileProvider) Destroy ¶
func (p *FileProvider) Destroy(sid string) error
Destroy deletes a session by session ID.
func (*FileProvider) Exist ¶
func (p *FileProvider) Exist(sid string) bool
Exist returns true if session with given ID exists.
func (*FileProvider) Init ¶
func (p *FileProvider) Init(maxlifetime int64, rootPath string) error
Init initializes file session provider with given root path.
func (*FileProvider) Read ¶
func (p *FileProvider) Read(sid string) (_ RawStore, err error)
Read returns raw session store by session ID.
func (*FileProvider) Regenerate ¶
func (p *FileProvider) Regenerate(oldsid, sid string) (_ RawStore, err error)
Regenerate regenerates a session store from old session ID to new one.
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
FileStore represents a file session store implementation.
func NewFileStore ¶
func NewFileStore(p *FileProvider, sid string, kv map[interface{}]interface{}) *FileStore
NewFileStore creates and returns a file session store.
func (*FileStore) Get ¶
func (s *FileStore) Get(key interface{}) interface{}
Get gets value by given key in session.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager represents a struct that contains session provider and its configuration.
func NewManager ¶
NewManager creates and returns a new session manager by given provider name and configuration. It returns an error when requested provider name isn't registered.
func (*Manager) RegenerateID ¶
func (m *Manager) RegenerateID(resp http.ResponseWriter, req *http.Request) (sess RawStore, err error)
RegenerateID regenerates a session store from old session ID to new one.
type MemProvider ¶
type MemProvider struct {
// contains filtered or unexported fields
}
MemProvider represents a in-memory session provider implementation.
func (*MemProvider) Count ¶
func (p *MemProvider) Count() int
Count counts and returns number of sessions.
func (*MemProvider) Destroy ¶
func (p *MemProvider) Destroy(sid string) error
Destroy deletes a session by session ID.
func (*MemProvider) Exist ¶
func (p *MemProvider) Exist(sid string) bool
Exist returns true if session with given ID exists.
func (*MemProvider) Init ¶
func (p *MemProvider) Init(maxLifetime int64, _ string) error
Init initializes memory session provider.
func (*MemProvider) Read ¶
func (p *MemProvider) Read(sid string) (_ RawStore, err error)
Read returns raw session store by session ID.
func (*MemProvider) Regenerate ¶
func (p *MemProvider) Regenerate(oldsid, sid string) (RawStore, error)
Regenerate regenerates a session store from old session ID to new one.
type MemStore ¶
type MemStore struct {
// contains filtered or unexported fields
}
MemStore represents a in-memory session store implementation.
func NewMemStore ¶
NewMemStore creates and returns a memory session store.
func (*MemStore) Get ¶
func (s *MemStore) Get(key interface{}) interface{}
Get gets value by given key in session.
type Options ¶
type Options struct { // Name of provider. Default is "memory". Provider string // Provider configuration, it's corresponding to provider. ProviderConfig string // Cookie name to save session ID. Default is "MacaronSession". CookieName string // Cookie path to store. Default is "/". CookiePath string // GC interval time in seconds. Default is 3600. Gclifetime int64 // Max life time in seconds. Default is whatever GC interval time is. Maxlifetime int64 // Use HTTPS only. Default is false. Secure bool // Cookie life time. Default is 0. CookieLifeTime int // SameSite set the cookie SameSite SameSite http.SameSite // Cookie domain name. Default is empty. Domain string // Session ID length. Default is 16. IDLength int // Ignore release for websocket. Default is false. IgnoreReleaseForWebSocket bool }
Options represents a struct for specifying configuration options for the session middleware.
func PrepareOptions ¶
PrepareOptions gives some default values for options
type Provider ¶
type Provider interface { // Init initializes session provider. Init(gclifetime int64, config string) error // Read returns raw session store by session ID. Read(sid string) (RawStore, error) // Exist returns true if session with given ID exists. Exist(sid string) bool // Destroy deletes a session by session ID. Destroy(sid string) error // Regenerate regenerates a session store from old session ID to new one. Regenerate(oldsid, sid string) (RawStore, error) // Count counts and returns number of sessions. Count() int // GC calls GC to clean expired sessions. GC() }
Provider is the interface that provides session manipulations.
type RawStore ¶
type RawStore interface { // Set sets value to given key in session. Set(interface{}, interface{}) error // Get gets value by given key in session. Get(interface{}) interface{} // Delete deletes a key from session. Delete(interface{}) error // ID returns current session ID. ID() string // Release releases session resource and save data to provider. Release() error // Flush deletes all session data. Flush() error }
RawStore is the interface that operates the session data.
type Store ¶
type Store interface { RawStore // Read returns raw session store by session ID. Read(string) (RawStore, error) // Destroy deletes a session. Destroy(http.ResponseWriter, *http.Request) error // RegenerateID regenerates a session store from old session ID to new one. RegenerateID(http.ResponseWriter, *http.Request) (RawStore, error) // Count counts and returns number of sessions. Count() int // GC calls GC to clean expired sessions. GC() }
Store is the interface that contains all data for one session process with specific ID.
func RegenerateSession ¶
RegenerateSession