session

package
v0.0.0-...-519d24f Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const SessionLoggerKey = "web.middleware.session"

SessionLoggerKey is a logger key for the middleware

Variables

View Source
var Default = &Middleware{
	Store:      NewMemorySessionStore(),
	CookieName: "yssk22-go-session",
	MaxAge:     7 * 24 * time.Hour,
	Domain:     "localhost",
	HttpOnly:   true,
	Path:       "/",
}

Default is a middleware instance with default value

Functions

func NewContext

func NewContext(ctx context.Context, s *Session) context.Context

NewContext returns a new context with he sesison.

Types

type MemorySessionStore

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

MemorySessionStore implements SessionStore on Memory

func NewMemorySessionStore

func NewMemorySessionStore() *MemorySessionStore

func (*MemorySessionStore) Del

func (s *MemorySessionStore) Del(ctx context.Context, session *Session) error

Del implements SessionStore#Del

func (*MemorySessionStore) Get

func (s *MemorySessionStore) Get(ctx context.Context, key uuid.UUID) (*Session, error)

Get implements SessionStore#Get

func (*MemorySessionStore) Set

func (s *MemorySessionStore) Set(ctx context.Context, session *Session) error

Set implements SessionStore#Set

func (*MemorySessionStore) String

func (s *MemorySessionStore) String() string

type Middleware

type Middleware struct {
	Store SessionStore
	//
	// Configurations for cookie that keeps session id.
	//
	CookieName string
	MaxAge     time.Duration
	Domain     string
	HttpOnly   bool
	Path       string
}

func NewMiddleware

func NewMiddleware(store SessionStore) *Middleware

NewMiddleware returns the *Middleware with default configurations.

func (*Middleware) Process

func (m *Middleware) Process(req *web.Request, next web.NextHandler) *response.Response

type Session

type Session struct {
	ID         uuid.UUID
	CSRFSecret uuid.UUID
	Timestamp  time.Time
	Data       map[string][]byte
	// contains filtered or unexported fields
}

Session is an object to represents session

func FromContext

func FromContext(ctx context.Context) *Session

FromContext returns a *Session from a context.

func FromRequest

func FromRequest(req *web.Request) *Session

FromRequest returns a *Session from a request.

func NewSession

func NewSession() *Session

NewSession returns a new *Session

func (*Session) Decode

func (s *Session) Decode(data string) error

Decode decodes a given `data` into *Session object

func (*Session) Del

func (s *Session) Del(key interface{}) error

Del delete the session data

func (*Session) Encode

func (s *Session) Encode() (string, error)

Encode returns a encoded strings of session data, which is passed to session store.

func (*Session) Get

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

Get sets the session data

func (*Session) IsExpired

func (s *Session) IsExpired(maxAge time.Duration) bool

IsExpired returns true if the session is expired

func (*Session) Set

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

Set sets the session data

type SessionStore

type SessionStore interface {
	Get(context.Context, uuid.UUID) (*Session, error)
	Set(context.Context, *Session) error
	Del(context.Context, *Session) error
}

SessionStore is an interface for session storage.

Directories

Path Synopsis
Package sessiontest provides session test helper
Package sessiontest provides session test helper

Jump to

Keyboard shortcuts

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