sessions

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCipher = errors.New("simpa-sessions: SID is not signed by backend, but for compability created a new session")

Functions

This section is empty.

Types

type Config

type Config struct {
	Name     string        `bson:"name" json:"name"`
	Value    string        `bson:"value" json:"value"`
	MaxAge   int           `bson:"maxage" json:"maxage"`
	Expires  time.Time     `bson:"expires" json:"expires"`
	Secure   bool          `bson:"secure" json:"secure"`
	HttpOnly bool          `bson:"httponly" json:"httponly"`
	SameSite http.SameSite `bson:"samesite" json:"samesite"`
}

Session Cookie cofig

type Session

type Session struct {
	ID     string                 `bson:"_id" json:"_id"`
	Values map[string]interface{} `bson:"values" json:"values"` // when marshaled should be encrypted through engine's crypter, when unmarshalled should decrypt and parse json
	Opts   *Config                `bson:"options" json:"options"`
	// contains filtered or unexported fields
}

Session object

func (*Session) Get

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

func (*Session) New

func (s *Session) New(r *http.Request, config *Config) (*Session, error)

func (*Session) SID

func (s *Session) SID() string

func (*Session) Save

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

func (*Session) Set

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

func (*Session) SetCrypter

func (s *Session) SetCrypter(crypt crypt.CrypterI)

func (*Session) SetStore

func (s *Session) SetStore(store Store)

type SessionI

type SessionI interface {
	// Creates or loads session from the database
	New(r *http.Request, config http.Cookie) (*Session, error)

	// saves session back to store
	Save() error

	// returns SID
	SID() string

	// sets key to map
	Set(key string, val interface{})

	// gets ley from map
	Get(key string) interface{}

	// sets store driver
	SetStore(Store)

	// sets crypter, should set it from engine
	SetCrypter(crypt.CrypterI)
	// contains filtered or unexported methods
}

type Store

type Store interface {
	Set(*Session) error
	Get(sid string) (*Session, error)
	Purge(sid string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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