Documentation
¶
Index ¶
- func AddConfigBuilder(t Type, f ConfigBuilder)
- type Config
- type ConfigBuilder
- type Conn
- type SessionConfig
- type Storage
- func (s *Storage) Close() error
- func (s *Storage) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *Storage) MaxAge(age int)
- func (s *Storage) New(r *http.Request, name string) (session *sessions.Session, err error)
- func (s *Storage) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConfigBuilder ¶
func AddConfigBuilder(t Type, f ConfigBuilder)
Types ¶
type Config ¶
Config is a config interface that every Conn SessionConfig would implement it
func BuildStorageConfig ¶
type ConfigBuilder ¶
type ConfigBuilder func() Config
type Conn ¶
type Conn interface {
// Load reads the session from the database.
// returns true if there is a session data in DB
Load(session *sessions.Session) (bool, error)
// Save stores the session in the database.
Save(session *sessions.Session) error
// Delete removes keys from the database if MaxAge<0
Delete(session *sessions.Session) error
// Close closes the database.
Close() error
}
Conn is the interface for underlying persistent database
type SessionConfig ¶
type SessionConfig struct {
// KeyPairs are used to generate securecookie.Codec,
// Should not change them after application is started,
// otherwise previously issued cookies will not be able to be decoded.
// Can be created using securecookie.GenerateRandomKey()
KeyPairs []string `json:"keyPairs"`
// Session Max-Age attribute present and given in seconds.
MaxAge int `json:"maxAge"`
// contains filtered or unexported fields
}
func (*SessionConfig) SetSecureCookie ¶
func (sc *SessionConfig) SetSecureCookie(val bool)
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage is a custom session store which provides an abstraction of common session store operations for multiple Key/Value databases.
func New ¶
func New(conn Conn, config SessionConfig) *Storage
func (*Storage) Get ¶
Get returns a session for the given name after adding it to the registry.
It returns a new session if the sessions doesn't exist. Access IsNew on the session to check if it is an existing session or a new one.
It returns a new session and an error if the session exists but could not be decoded or be expired.
func (*Storage) MaxAge ¶
MaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting options.MaxAge = -1 for that session.
func (*Storage) New ¶
New returns a session for the given name without adding it to the registry.
The difference between New() and Get() is that calling New() twice will decode the session data twice, while Get() registers and reuses the same decoded session after the first call. Get() calls New() internally if there's no data in cache.
func (*Storage) Save ¶
Save saves a single session to the underlying database and save the encoded session id to cookie of the response.
If the options.MaxAge of the session is <= 0 then the session will be deleted from the store path. With this process it enforces the properly session cookie handling so no need to trust in the cookie management in the web browser.