session

package
v0.0.0-...-1ad4281 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilKey returned when key has 0 or less length
	ErrNilKey = errors.New("Session: Error 0 length key")
	// ErrNilValue returned when value is nil
	ErrNilValue = errors.New("Session: Error nil value")
	// ErrValueType returned when value type is invalid
	ErrValueType = errors.New("Session: Error invalid value type")
)
View Source
var ErrNoSession = errors.New("Error No Session")

ErrNoSession returned by Data Get on no session found

Functions

This section is empty.

Types

type Cookie struct {
	// Name of Cookie NOT Value
	Name     string
	Domain   string
	Path     string
	Secure   bool
	HTTPOnly bool
	SameSite string
}

Cookie struct

type Data

type Data interface {
	// Returns session, error
	Get(key string) (*Session, error)
	Set(session *Session) error
	Delete(key string) error
}

Data interface of storage of session

type Key

type Key struct {
	// Length is passed to generator
	// Min/default value of 16
	Length int
	// Generator generates session id
	Generator func(int) string
}

Key struct

type Session

type Session struct {
	// Created time.Time
	Created time.Time `msg:"created"`
	// Expires time.Time
	Expires time.Time `msg:"expires"`
	// Status of session
	Status Status `msg:"status"`
	// Key session identifier
	Key string `msg:"key"`
	// Data of session
	Data map[string]interface{} `msg:"data"`
	// contains filtered or unexported fields
}

Session is session

func (*Session) Create

func (s *Session) Create(key string)

Create new Session

func (*Session) DecodeMsg

func (z *Session) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Session) Delete

func (s *Session) Delete()

Delete session does not regenerate

func (*Session) EncodeMsg

func (z *Session) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Session) Get

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

Get session value

func (*Session) GetBytes

func (s *Session) GetBytes(key string) ([]byte, error)

GetBytes from session

func (*Session) Init

func (s *Session) Init(store *Store)

Init add Store and mutex to session

func (*Session) MarshalMsg

func (z *Session) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Session) Msgsize

func (z *Session) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Session) Regenerate

func (s *Session) Regenerate()

Regenerate Session

func (*Session) Set

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

Set session value

func (*Session) UnmarshalMsg

func (z *Session) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Session) Updated

func (s *Session) Updated()

Updated updates expires and status

type Status

type Status int8

Status of Session

const (
	// Created Session Status
	Created Status = iota
	// NotUpdated Session Status
	NotUpdated
	// Updated Session Status
	Updated
	// Deleted Session Status
	Deleted
)

func (*Status) DecodeMsg

func (z *Status) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Status) EncodeMsg

func (z Status) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Status) MarshalMsg

func (z Status) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Status) Msgsize

func (z Status) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Status) UnmarshalMsg

func (z *Status) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Store

type Store struct {
	// MaxLife of session since creation
	MaxLife time.Duration
	// Expiration max time session can go unused
	Expiration time.Duration
	// Session Cookie
	Cookie Cookie
	// Data interface for interacting with session store db
	Data Data
	// Key struct (Length, Generator)
	Key Key
}

Store session storage

func New

func New(store *Store) *Store

New Store w/ value checking

TODO: finish checking for all values

func (*Store) Get

func (s *Store) Get(c *fiber.Ctx) *Session

Get session from store if no session is found

func (*Store) Set

func (s *Store) Set(c *fiber.Ctx)

Set session to store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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