sessions

package
v0.0.0-...-db3ccfa Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisStore

type RedisStore struct {
	// CookieName is the name of the session cookie.
	CookieName string

	// Session ID length (ie cookie value).
	IDLength int
	// contains filtered or unexported fields
}

RedisStore implements a session store which uses Redis as its underlying data store.

func NewRedisStore

func NewRedisStore(network, address, cookieName string) (*RedisStore, error)

NewRedisStore returns a session store that uses Redis for storage. Redis runs on tcp port 6379 by default.

func (*RedisStore) Close

func (rs *RedisStore) Close() error

Close closes the underlying redis resources.

func (*RedisStore) Get

func (rs *RedisStore) Get(r *http.Request) (*Session, error)

Get returns a session from the store, or, if absent, it creates one. Call Save to store the session and set a Set-Cookie header.

func (*RedisStore) RedisKey

func (rs *RedisStore) RedisKey(sessionID string) string

RedisKey returns the key the session data is stored in Redis.

func (*RedisStore) Save

func (rs *RedisStore) Save(w http.ResponseWriter, r *http.Request, s *Session) error

Save saves the session values to redis and, if the session is new, it adds a Set-Cookie header to ResponseWriter.

type Session

type Session struct {

	// ID is the value of the session cookie.
	ID string

	Values map[string]interface{}

	// CookieSet indicates whether this is a new session or not.
	CookieSet bool
	// contains filtered or unexported fields
}

Session stores a map of session values.

func (*Session) Clear

func (s *Session) Clear()

Clear sets s.Values to a new map. The new map is not persisted to the store until Save is called.

func (*Session) Save

func (s *Session) Save(w http.ResponseWriter, r *http.Request) error

Save implements Store.Save method.

func (*Session) Store

func (s *Session) Store() Store

Store returns the underlying store of session.

type Store

type Store interface {
	// Get returns an already stored session or, if none exists, a new one (in
	// which case it's not persisted to the store until Save is called). Check
	// session.CookieSet value to determine if the session is a new one.
	Get(r *http.Request) (*Session, error)

	// Save saves the session to the underlying store and sets http cookie
	// headers.
	Save(w http.ResponseWriter, r *http.Request, s *Session) error
}

Store is a session store.

Jump to

Keyboard shortcuts

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