Documentation ¶
Overview ¶
Package sessionmw provides a Goji v2 context aware session middleware.
Index ¶
- Constants
- Variables
- func CookieName(ctxt context.Context) string
- func Delete(ctxt context.Context, key string)
- func Destroy(ctxt context.Context, res ...http.ResponseWriter) error
- func Get(ctxt context.Context, key string) (interface{}, bool)
- func ID(ctxt context.Context) string
- func Set(ctxt context.Context, key string, val interface{})
- type Config
- type IDFn
- type Store
Constants ¶
const (
// DefaultCookieName is the default cookie name.
DefaultCookieName = "SESSID"
)
Variables ¶
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound is the error returned by sessionmw.Store providers when a session cannot be found.
Functions ¶
func CookieName ¶
CookieName retrieves the cookie name from the context.
func Destroy ¶
func Destroy(ctxt context.Context, res ...http.ResponseWriter) error
Destroy destroys a session in the underlying session store.
Note that any existing values will continue to remain in the context after destruction. The context should be closed (or destroyed).
If the optional http.ResponseWriter is provided, then an expired cookie will be added to the response headers.
Types ¶
type Config ¶
type Config struct { // Secret is Secret []byte BlockSecret []byte // Store is the underlying session store. Store Store // IDFn is the id generation func. IDFn IDFn // Name is the cookie name. Name string // Path is the cookie path. Path string // Domain is the cookie domain. Domain string // Expires is the cookie expiration time. Expires time.Time // MaxAge is the cookie max age. MaxAge time.Duration // Secure is the cookie secure flag. Secure bool // HttpOnly is the cookie http only flag. HttpOnly bool }
Config contains the configuration parameters for the session middleware.
type Store ¶
type Store interface { // Write retrieves the session for the provided id. Write(key string, obj interface{}) error // Read saves the session for the provided id. // // If the provided id already exists in storage, then it will be // overwritten. Read(key string) (interface{}, error) // Destroy permanently destroys the session with the provided id. Erase(key string) error }
Store is the common interface for session storage.
Please see github.com/knq/kv.Store for a compatible store.