Documentation ¶
Index ¶
- Variables
- func GobEncoder(data Data) ([]byte, error)
- func Sessioner(opts ...Options) flamego.Handler
- type BaseSession
- func (s *BaseSession) Delete(key interface{})
- func (s *BaseSession) Encode() ([]byte, error)
- func (s *BaseSession) Flush()
- func (s *BaseSession) Get(key interface{}) interface{}
- func (s *BaseSession) HasChanged() bool
- func (s *BaseSession) ID() string
- func (s *BaseSession) RegenerateID(w http.ResponseWriter, r *http.Request) error
- func (s *BaseSession) Set(key, val interface{})
- func (s *BaseSession) SetFlash(val interface{})
- type CookieOptions
- type Data
- type Decoder
- type Encoder
- type FileConfig
- type Flash
- type IDWriter
- type Initer
- type MemoryConfig
- type Options
- type Session
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrMinimumSIDLength = errors.Errorf("the SID does not have the minimum required length %d", minimumSIDLength)
Functions ¶
func GobEncoder ¶
GobEncoder is a session data encoder using Gob.
Types ¶
type BaseSession ¶
type BaseSession struct {
// contains filtered or unexported fields
}
BaseSession implements basic operations for the session data.
func NewBaseSession ¶
func NewBaseSession(sid string, encoder Encoder, idWriter IDWriter) *BaseSession
NewBaseSession returns a new BaseSession with given session ID.
func NewBaseSessionWithData ¶ added in v1.5.1
func NewBaseSessionWithData(sid string, encoder Encoder, idWriter IDWriter, data Data) *BaseSession
NewBaseSessionWithData returns a new BaseSession with given session ID and initial data.
func (*BaseSession) Delete ¶
func (s *BaseSession) Delete(key interface{})
func (*BaseSession) Encode ¶
func (s *BaseSession) Encode() ([]byte, error)
func (*BaseSession) Flush ¶
func (s *BaseSession) Flush()
func (*BaseSession) Get ¶
func (s *BaseSession) Get(key interface{}) interface{}
func (*BaseSession) HasChanged ¶ added in v1.6.1
func (s *BaseSession) HasChanged() bool
func (*BaseSession) ID ¶
func (s *BaseSession) ID() string
func (*BaseSession) RegenerateID ¶ added in v1.6.4
func (s *BaseSession) RegenerateID(w http.ResponseWriter, r *http.Request) error
func (*BaseSession) Set ¶
func (s *BaseSession) Set(key, val interface{})
func (*BaseSession) SetFlash ¶
func (s *BaseSession) SetFlash(val interface{})
type CookieOptions ¶
type CookieOptions struct { // Name is the name of the cookie. Default is "flamego_session". Name string // Path is the Path attribute of the cookie. Default is "/". Path string // Domain is the Domain attribute of the cookie. Default is not set. Domain string // MaxAge is the MaxAge attribute of the cookie. Default is not set. MaxAge int // Secure specifies whether to set Secure for the cookie. Secure bool // HTTPOnly specifies whether to set HTTPOnly for the cookie. HTTPOnly bool // SameSite is the SameSite attribute of the cookie. Default is // http.SameSiteLaxMode. SameSite http.SameSite }
CookieOptions contains options for setting HTTP cookies.
type Data ¶
type Data map[interface{}]interface{}
Data is the data structure for storing session data.
func GobDecoder ¶
GobDecoder is a session data decoder using Gob.
type FileConfig ¶
type FileConfig struct { // Lifetime is the duration to have no access to a session before being // recycled. Default is 3600 seconds. Lifetime time.Duration // RootDir is the root directory of file session items stored on the local file // system. Default is "sessions". RootDir string // Encoder is the encoder to encode session data. Default is GobEncoder. Encoder Encoder // Decoder is the decoder to decode session data. Default is GobDecoder. Decoder Decoder // contains filtered or unexported fields }
FileConfig contains options for the file session store.
type Flash ¶
type Flash interface{}
Flash is anything that gets retrieved and deleted as soon as the next request happens.
type IDWriter ¶ added in v1.6.5
type IDWriter func(w http.ResponseWriter, r *http.Request, sid string)
IDWriter is a function that writes the session ID to client (browser).
type Initer ¶
Initer takes arbitrary number of arguments needed for initialization and returns an initialized session store.
func FileIniter ¶
func FileIniter() Initer
FileIniter returns the Initer for the file session store.
func MemoryIniter ¶
func MemoryIniter() Initer
MemoryIniter returns the Initer for the memory session store.
type MemoryConfig ¶
type MemoryConfig struct { // Lifetime is the duration to have no access to a session before being // recycled. Default is 3600 seconds. Lifetime time.Duration // contains filtered or unexported fields }
MemoryConfig contains options for the memory session store.
type Options ¶
type Options struct { // Initer is the initialization function of the session store. Default is // session.MemoryIniter. Initer Initer // Config is the configuration object to be passed to the Initer for the session // store. Config interface{} // Cookie is a set of options for setting HTTP cookies. Cookie CookieOptions // IDLength specifies the length of session IDs. Default is 16. IDLength int // GCInterval is the time interval for GC operations. Default is 5 minutes. GCInterval time.Duration // ErrorFunc is the function used to print errors when something went wrong on // the background. Default is to drop errors silently. ErrorFunc func(err error) // ReadIDFunc is the function to read session ID from the request. Default is // reading from cookie. ReadIDFunc func(r *http.Request) string // WriteIDFunc is the function to write session ID to the response. Default is // writing to cookie. The `created` argument indicates whether a new session was // created in the session store. WriteIDFunc func(w http.ResponseWriter, r *http.Request, sid string, created bool) }
Options contains options for the session.Sessioner middleware.
type Session ¶
type Session interface { // ID returns the session ID. ID() string // RegenerateID regenerates the session ID. RegenerateID(w http.ResponseWriter, r *http.Request) error // Get returns the value of given key in the session. It returns nil if no such // key exists. Get(key interface{}) interface{} // Set sets the value of given key in the session. Set(key, val interface{}) // SetFlash sets the flash to be the given value in the session. SetFlash(val interface{}) // Delete deletes a key from the session. Delete(key interface{}) // Flush wipes out all existing data in the session. Flush() // Encode encodes session data to binary. Encode() ([]byte, error) // HasChanged returns whether the session has changed. HasChanged() bool }
Session is a session for the current request.
type Store ¶
type Store interface { // Exist returns true of the session with given ID exists. Exist(ctx context.Context, sid string) bool // Read returns the session with given ID. If a session with the ID does not // exist, a new session with the same ID is created and returned. Read(ctx context.Context, sid string) (Session, error) // Destroy deletes session with given ID from the session store completely. Destroy(ctx context.Context, sid string) error // Touch updates the expiry time of the session with given ID. It does nothing // if there is no session associated with the ID. Touch(ctx context.Context, sid string) error // Save persists session data to the session store. Save(ctx context.Context, session Session) error // GC performs a GC operation on the session store. GC(ctx context.Context) error }
Store is a session store with capabilities of checking, reading, destroying and GC sessions.