session

package
v0.0.0-...-86833b7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultManager = New(time.Hour, time.Hour*2, file.New("./resources/sessions"), GobSerializer{}, RandGenerator{})

	DefaultCookieOptions = &CookieOptions{
		Name: "__gsid",
	}
)
View Source
var (
	SessionType = reflect.TypeOf((*Session)(nil))
)

Functions

func Persist

func Persist(c *container.Registry, i interface{}) error

func PersistKey

func PersistKey(c *container.Registry, key string, i interface{}) error

Types

type Bundle

type Bundle struct {
	CookieOptions *CookieOptions
	Manager       *Manager
}

func (*Bundle) Bootstrap

func (component *Bundle) Bootstrap(a *app.Kernel)

func (*Bundle) Handle

func (component *Bundle) Handle(ctx *request.Context)

type CookieOptions

type CookieOptions struct {
	Name   string
	Path   string
	Domain string

	MaxAge int

	Expires time.Time

	Secure   bool
	HttpOnly bool
}

type GobSerializer

type GobSerializer struct{}

func (GobSerializer) Serialize

func (serializer GobSerializer) Serialize(src interface{}, writer io.Writer) error

func (GobSerializer) Unserialize

func (serializer GobSerializer) Unserialize(dst interface{}, reader io.Reader) error

type IdGenerator

type IdGenerator interface {
	Generate(id, name string) string
}

IdGenerator this interface represents an id generator

type Manager

type Manager struct {
	Global     *container.Registry
	Generator  IdGenerator
	Store      Store
	Serializer Serializer
	Duration   time.Duration
	// contains filtered or unexported fields
}

func New

func New(gcEvery time.Duration, duration time.Duration, store Store, serializer Serializer, generator IdGenerator) *Manager

New returns a new session

func (*Manager) Open

func (manager *Manager) Open(ctx *container.Registry, sessionName string, dst interface{}) error

Open load stored session and un serialize the stored data into dst

func (*Manager) Remove

func (manager *Manager) Remove(ctx *container.Registry, sessionName string) error

Remove remove the session

func (*Manager) Save

func (manager *Manager) Save(ctx *container.Registry, sessionName string, session interface{}) error

Save save the session

type RandGenerator

type RandGenerator struct{}

func (RandGenerator) Generate

func (RandGenerator) Generate(id, name string) string

type Serializer

type Serializer interface {
	Serialize(session interface{}, w io.Writer) error
	Unserialize(session interface{}, r io.Reader) error
}

type Session

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

func GetSessionManager

func GetSessionManager(cdi *container.Registry) *Session

func (*Session) Contains

func (c *Session) Contains(key string) (contains bool)

func (*Session) Get

func (c *Session) Get(name string) (value interface{})

func (*Session) ID

func (c *Session) ID() string

func (*Session) Lookup

func (c *Session) Lookup(name string) (data interface{}, found bool)

func (*Session) Set

func (c *Session) Set(name string, val interface{})

Set sets a key in the session

func (*Session) Unset

func (c *Session) Unset(keys ...string)

Unset deletes a key in the session map

type Store

type Store interface {
	Reader(c *container.Registry, name string, after time.Time) (io.ReadCloser, error)
	Writer(c *container.Registry, name string) (io.WriteCloser, error)
	Remove(c *container.Registry, name string) error
	GC(c *container.Registry, before time.Time)
}

Directories

Path Synopsis
store

Jump to

Keyboard shortcuts

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