whsess

package
v0.0.0-...-3f30213 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

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

Functions

func HandlerWithStore

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

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

Types

type CookieOptions

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

type CookieStore

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

func NewCookieStore

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

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

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

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

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

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

func Load

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

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

Clear clears the session using the appropriate mechanism.

func (*Session) Save

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

Save saves the session using the appropriate mechanism.

type SessionData

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

type Store

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
}

Jump to

Keyboard shortcuts

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