session

package
v0.0.0-...-5c8b849 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package session provides session management capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Type      string `toml:"store"`
	HTTPSOnly bool   `toml:"secure_only"`
	Secret    string `toml:"secret"`

	FileConfig `toml:"file"`
}

Config is the configuration for a session manager.

type FileConfig

type FileConfig struct {
	StoragePath string `toml:"storage_path"`
}

FileConfig represents a configuration for file-based sessions.

type Manager

type Manager interface {
	// Get loads or creates a session for the given request.
	Get(*http.Request, http.ResponseWriter) (*Session, error)

	// Invalidate destroys any session related to the given request, if any.
	Invalidate(*http.Request, http.ResponseWriter)

	// Regenerate the given session, returning a new session or error.
	Regenerate(*Session, http.ResponseWriter) error
	// contains filtered or unexported methods
}

A Manager handles loading and saving of sessions.

func NewManager

func NewManager(c Config, l log.Logger) Manager

NewManager creates a new session manager with the given configuration.

type Session

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

A Session is a semi-persistent user storage container.

Sessions are created by the Session middleware. Each Session is expected to live for only the associated Request'c lifetime and are not designed to be operated on concurrently.

func (*Session) Bytes

func (s *Session) Bytes(key string) ([]byte, bool)

Bytes attempts to retrieve the value for the given key as a byte slice.

func (*Session) CheckCSRF

func (s *Session) CheckCSRF(key string, suspect string) bool

CheckCSRF checks the given suspect token against the stored CSRF token.

Calling this method removes the value, if any, from the session.

func (*Session) Flash

func (s *Session) Flash(key string) string

Flash returns the stored flash message with the given key or an empty string.

Calling this method removes the value stored in the session.

func (*Session) Flush

func (s *Session) Flush() error

Flush saves the session to persistent storage.

func (*Session) Get

func (s *Session) Get(key string) (interface{}, bool)

Get returns the value for the given string.

func (*Session) Int

func (s *Session) Int(key string) (int, bool)

Int attempts to retrieve the value for the given key as an int.

func (*Session) NewCSRF

func (s *Session) NewCSRF(key string) string

NewCSRF creates a one-time use random token to be used as a CSRF token.

Each form should contain a CSRF token that is generated when the form is shown and validated when a form is submitted.

func (*Session) Remove

func (s *Session) Remove(key string) bool

Remove removes the given key from the session.

func (*Session) Set

func (s *Session) Set(key string, value interface{})

Set sets the given key to the given value.

func (*Session) SetFlash

func (s *Session) SetFlash(key string, message string)

SetFlash adds a message to the session with the given key.

Flash messages are messages intended to be shown on the next page load. Reading a flash removes it from the session.

func (*Session) String

func (s *Session) String(key string) (string, bool)

String attempts to retrieve the value for the given key as a string.

Jump to

Keyboard shortcuts

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