session

package module
v0.0.0-...-d41676d Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2017 License: MIT Imports: 10 Imported by: 1

README

session

HTTP Sessions store agnostic implementation for Go

Documentation

Index

Constants

View Source
const DefaultCookieName = "GOSESSION"
View Source
const DefaultIPStrict = false
View Source
const DefaultTTL = 24 * time.Hour

Variables

View Source
var DefaultCookie = http.Cookie{
	Name:   DefaultCookieName,
	MaxAge: int(DefaultTTL.Seconds()),
	Path:   "/",
}
View Source
var ErrorEmptyManager = fmt.Errorf("Empty manager")

Functions

func NewMiddleware

func NewMiddleware(manager *Manager) func(http.Handler) http.Handler

func ToCtx

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

Types

type Manager

type Manager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func DefaultManager

func DefaultManager(store Store) *Manager

func NewManager

func NewManager(emptyCookie http.Cookie, ipStrict bool, store Store) *Manager

func (*Manager) Delete

func (m *Manager) Delete(session string) error

func (*Manager) Get

func (m *Manager) Get(session, key string) (interface{}, error)

func (*Manager) Session

func (m *Manager) Session(w http.ResponseWriter, r *http.Request) *Session

func (*Manager) Set

func (m *Manager) Set(session, key string, v interface{}) error

type Middleware

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

func (*Middleware) ServeHTTP

func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Session

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

func FromCtx

func FromCtx(ctx context.Context) (s *Session)

func (*Session) Get

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

Get gets variable from Session

func (*Session) Name

func (s *Session) Name() string

Name gets name of the Session

func (*Session) Set

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

Set sets variable in Session

type Store

type Store interface {
	Get(key string) ([]byte, error)
	Set(key string, value []byte, ttl time.Duration) error
	Delete(key string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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