httpssn

package
v0.0.0-...-e1e9d1d Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package httpssn defines the standard interfaces for HTTP sessions, which may be implemented as cookies, file-system based, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flashes

type Flashes struct {
	// Store is the session store to use.
	Store Store

	// SessionName is the name of the session to use in the store.
	SessionName string

	// SessionKey is the key name under which to store flash messages in the
	// session.
	SessionKey string
}

Flashes allows storing and retrieval of flash messages in a session store.

func (*Flashes) Add

func (f *Flashes) Add(r *http.Request, msg interface{}) error

Add adds msg as a flash message for the provided request. Note that msg must be of a valid type for the implementation-specific constraints of the session store.

func (*Flashes) Get

func (f *Flashes) Get(r *http.Request) ([]interface{}, error)

Get returns the list of flash messages from the store. On successful return, the flash messages are cleared from the store.

type MockSession

type MockSession struct {
	NameFunc   func() string
	IsNewFunc  func() bool
	GetFunc    func(string) interface{}
	SetFunc    func(string, interface{})
	UnsetFunc  func(string)
	DeleteFunc func()
}

MockSession is a test mock for the Session interface.

func (*MockSession) Delete

func (m *MockSession) Delete()

func (*MockSession) Get

func (m *MockSession) Get(key string) interface{}

func (*MockSession) IsNew

func (m *MockSession) IsNew() bool

func (*MockSession) Name

func (m *MockSession) Name() string

func (*MockSession) Set

func (m *MockSession) Set(key string, v interface{})

func (*MockSession) Unset

func (m *MockSession) Unset(key string)

type MockStore

type MockStore struct {
	GetOrCreateFunc func(*http.Request, string) (Session, error)
	SaveFunc        func(http.ResponseWriter, *http.Request, Session) error
}

MockStore is a test mock for the Store interface.

func (*MockStore) GetOrCreate

func (m *MockStore) GetOrCreate(req *http.Request, name string) (Session, error)

func (*MockStore) Save

func (m *MockStore) Save(w http.ResponseWriter, r *http.Request, ssn Session) error

type Session

type Session interface {
	// Name is the name of the session.
	Name() string

	// IsNew indicates if the session was created by the current request.
	IsNew() bool

	// Get returns the value associated with key in the session.
	Get(key string) interface{}

	// Set sets the value v for the key in the session.
	Set(key string, v interface{})

	// Unset unsets the key in the session.
	Unset(key string)

	// Delete marks the session for deletion. Actual deletion is only
	// performed when the session is saved in its store.
	Delete()
}

Session defines the methods to implement a Session managed by a Store.

type Store

type Store interface {
	// GetOrCreate returns the session of the specified name for that request. If
	// no such session currently exists, it creates it.
	GetOrCreate(r *http.Request, name string) (Session, error)

	// Save saves the provided session for that request.
	Save(w http.ResponseWriter, r *http.Request, ssn Session) error
}

Store defines the methods to implement an HTTP session store.

Jump to

Keyboard shortcuts

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