Documentation ¶
Overview ¶
Package session implements routines and interfaces for handling users session (creating, killing, authorizing).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoRenewers = errors.New("session: you haven't provided any renewers")
ErrNoRenewers is returned by Renewer composed by RenewerComposite when there are no renewers to run.
Functions ¶
func Guard ¶
Guard returns http middleware which guards from clients accessing given handler without valid session.
func WithOptions ¶
func WithOptions(ctx context.Context, state State, args WithOptionsArguments) error
WithOptions applies options to given state and saves it. It does nothing more thatn regular Saver if you won't provide options.
Types ¶
type Builder ¶
Builder contains arguments and dependencies for building new session for user with given ID.
type Killer ¶
type Killer interface { // Kill is method for purging session. Kill(context.Context, http.ResponseWriter) error }
Killer purges session. It can make given session implementation expired.
type Renewer ¶
type Renewer interface { // Renew is method for restoring session from // provided request data from client. Renew(*http.Request) (*State, error) }
Renewer retrieves session data from http request.
func RenewerComposite ¶
RenewerComposite compose multiple Renewers into single one. Composed renewer will run each renewer till the first will successfully return any State.
type Saver ¶
type Saver interface { // Save is method for returning session data or // session identifier to client. Save(context.Context, http.ResponseWriter, State) error }
Saver saves data in database and returns public information about session to client.
type State ¶
type State struct { // ID is unique identifier of single session. ID string // UserID is user ID of session's owner. UserID string // Nickname is user name of session's owner. Nickname string // Values are key/value storage for additional // session data. Values map[string]interface{} }
State holds common data for storing in single user session.
type WithOptionsArguments ¶
type WithOptionsArguments struct { Saver Saver Writer http.ResponseWriter Options []Option }
WithOptionsArguments holds arguments for WithOptions function. All arguments are required.