context

package
v0.0.0-...-e64dc14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2016 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpired        = errors.New("Session expired")
	ErrNotExist       = errors.New("Session does not exist")
	ErrCookieNotExist = errors.New("Session cookie does not exist")
)

Functions

func CleanupSessions

func CleanupSessions(path string, age time.Duration) error

CleanupSessions is a helper function for clearing all session data from the filesystem older than a given age. If the age is 0, all session data is removed.

Types

type BaseCtxKey

type BaseCtxKey string

type Context

type Context interface {
	Get(*http.Request, interface{}) (interface{}, bool)
	GetAll(*http.Request) ContextData
	Set(*http.Request, interface{}, interface{})
	GetGlobal(interface{}) (interface{}, bool)
	SetGlobal(interface{}, interface{})
	DeleteAll(*http.Request)
	Delete(*http.Request, interface{})
}

func NewContext

func NewContext() Context

NewContext creates a new Context object.

type ContextData

type ContextData map[interface{}]interface{}

type FlashValues

type FlashValues map[interface{}]interface{}

type Session

type Session interface {
	Read(*http.Request, Context) error
	Write(http.ResponseWriter) error
	Name() string
	SetName(string)
	MaxAge() time.Duration
	SetMaxAge(time.Duration)
	CookieName() string
	SetCookieName(string)

	Set(interface{}, interface{})
	Get(interface{}) (interface{}, bool)
	GetAll() SessionValues
	DeleteAll()
	Delete(interface{})
	Flash(interface{}) (interface{}, bool)
	SetFlash(interface{}, interface{})
}

The Session represents persistent user data. Its Name field is how it is identified. The secret is used to salt the hmac, sent along the data to the client as a cookie. The data is a base64 encoded string, containing the session name and date showing when it was last used. The actual session data is stored in the filesystem, in a directory specified by the Path field. The data is serialized using encoding/gob, therefore any custom data type should be registered with it. The MaxAge field specifies a duration, after which an unused session will get cleared of its data and marked as expired. It is also used as the max-age and expires fields of the session cookie.

func NewSession

func NewSession(secret, cipher []byte, path string) Session

NewSession creates a new session object.

type SessionGenerator

type SessionGenerator func(secret, cipher []byte, path string) Session

type SessionValues

type SessionValues map[interface{}]interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL