webhelp.v1: gopkg.in/webhelp.v1/whsess Index | Files

package whsess

import "gopkg.in/webhelp.v1/whsess"

package whsess is a lightweight session storage mechanism for the webhelp package. Attempting to be a combination of minimal and useful. Implementing the Store interface is all one must do to provide a different session storage mechanism.

Index

Package Files

cookie.go store.go

Variables

var (
    SessionError = errors.NewClass("session")
)

func HandlerWithStore Uses

func HandlerWithStore(s Store, h http.Handler) http.Handler

HandlerWithStore wraps a webhelp.Handler such that Load works with contexts provided in that Handler.

type CookieOptions Uses

type CookieOptions struct {
    Path     string
    Domain   string
    MaxAge   int
    Secure   bool
    HttpOnly bool
}

type CookieStore Uses

type CookieStore struct {
    Options CookieOptions
    // contains filtered or unexported fields
}

func NewCookieStore Uses

func NewCookieStore(secretKey []byte) *CookieStore

NewCookieStore creates a secure cookie store with default settings. Configure the Options field further if additional settings are required.

func NewLazyCookieStore Uses

func NewLazyCookieStore(secretKey func(context.Context) ([]byte, error)) (
    cs *CookieStore)

NewLazyCookieStore is like NewCookieStore but loads the secretKey using the provided callback once. This is useful for delayed initialization after the first request for something like App Engine where you can't interact with a database without a context.

func (*CookieStore) Clear Uses

func (cs *CookieStore) Clear(ctx context.Context, w http.ResponseWriter,
    namespace string) error

Clear implements the Store interface. Not expected to be used directly.

func (*CookieStore) Load Uses

func (cs *CookieStore) Load(ctx context.Context, r *http.Request,
    namespace string) (rv SessionData, err error)

Load implements the Store interface. Not expected to be used directly.

func (*CookieStore) Save Uses

func (cs *CookieStore) Save(ctx context.Context, w http.ResponseWriter,
    namespace string, s SessionData) error

Save implements the Store interface. Not expected to be used directly.

type Session Uses

type Session struct {
    SessionData
    // contains filtered or unexported fields
}

func Load Uses

func Load(ctx context.Context, namespace string) (*Session, error)

Load will return the current session, creating one if necessary. This will fail if a store wasn't installed with HandlerWithStore somewhere up the call chain.

func (*Session) Clear Uses

func (s *Session) Clear(ctx context.Context, w http.ResponseWriter) error

Clear clears the session using the appropriate mechanism.

func (*Session) Save Uses

func (s *Session) Save(ctx context.Context, w http.ResponseWriter) error

Save saves the session using the appropriate mechanism.

type SessionData Uses

type SessionData struct {
    New    bool
    Values map[interface{}]interface{}
}

type Store Uses

type Store interface {
    Load(ctx context.Context, r *http.Request, namespace string) (
        SessionData, error)
    Save(ctx context.Context, w http.ResponseWriter,
        namespace string, s SessionData) error
    Clear(ctx context.Context, w http.ResponseWriter, namespace string) error
}

Package whsess imports 13 packages (graph) and is imported by 3 packages. Updated 2017-06-01. Refresh now. Tools for package owners.