gomemssn

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

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

Go to latest
Published: Dec 7, 2014 License: MIT Imports: 10 Imported by: 0

README

gomemssn

simple http sessions with memcache in go

Documentation

Overview

simplistic http sessions based on memcache, with in-memory stub for development

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	TemplateCookie    *http.Cookie     // this cookie is copied and the value modified for each one written to the client
	Expiration        time.Duration    // how long until session expiration - passed back to memcache
	Client            *memcache.Client // the memcache client or nil to mean store in memory (stub for development)
	MemcacheKeyPrefix string           // prefix memcache keys with this
	// contains filtered or unexported fields
}

func NewManager

func NewManager(client *memcache.Client, keyPrefix string) *Manager

NewManager returns a new *Manager with sensible defaults. You need to provide the memcache client and an optional prefix for the keys we store in memcache.

func (*Manager) MustSession

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

func (*Manager) MustWriteSession

func (m *Manager) MustWriteSession(w http.ResponseWriter, s *Session)

func (*Manager) Session

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

Get or create the session object, sets the appropriate cookie, does not write to the backing store

func (*Manager) WriteSession

func (m *Manager) WriteSession(w http.ResponseWriter, s *Session) error

write the actual session back to he memcache backend

type Session

type Session struct {
	Key    string       // the key for this session
	Cookie *http.Cookie // the cookie we will write to the client
	Values Values       // values of the session
}

func (*Session) AddFlash

func (s *Session) AddFlash(v interface{})

convenience function to add a "flash message" to this session - uses the key "_flashes"

func (*Session) Flashes

func (s *Session) Flashes() []interface{}

pops the "flash messages" from this session

type Values

type Values map[string]interface{}

func (Values) GetBool

func (v Values) GetBool(key string) bool

func (Values) GetFloat64

func (v Values) GetFloat64(key string) float64

func (Values) GetInt64

func (v Values) GetInt64(key string) int64

func (Values) GetString

func (v Values) GetString(key string) string

func (Values) SetBool

func (v Values) SetBool(key string, val bool)

func (Values) SetFloat64

func (v Values) SetFloat64(key string, val float64)

func (Values) SetInt64

func (v Values) SetInt64(key string, val int64)

func (Values) SetString

func (v Values) SetString(key string, val string)

Jump to

Keyboard shortcuts

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