session

package
v0.0.0-...-ea61863 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2014 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateID

func GenerateID() string

func Register

func Register(name string, d Driver) error

func RegisterCodec

func RegisterCodec(name string, codec Codec) error

Types

type Codec

type Codec interface {
	Encode(values map[interface{}]interface{}) ([]byte, error)
	Decode(buf []byte) (map[interface{}]interface{}, error)
}

codec for session encode and decode

func GetCodec

func GetCodec(name string) (Codec, error)

get codec by name

type Driver

type Driver interface {
	Open(jsonConfig json.RawMessage) (Store, error)
}

type GobCodec

type GobCodec struct {
}

func (GobCodec) Decode

func (c GobCodec) Decode(data []byte) (map[interface{}]interface{}, error)

func (GobCodec) Encode

func (c GobCodec) Encode(values map[interface{}]interface{}) ([]byte, error)

type RedisDriver

type RedisDriver struct {
}

func (RedisDriver) Open

func (d RedisDriver) Open(jsonConfig json.RawMessage) (Store, error)

json config: json encode RedisStoreConfig

type RedisStore

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

func (*RedisStore) Delete

func (store *RedisStore) Delete(s *Session) error

func (*RedisStore) Get

func (store *RedisStore) Get(id string) (*Session, error)

func (*RedisStore) Save

func (store *RedisStore) Save(s *Session) error

type RedisStoreConfig

type RedisStoreConfig struct {
	Password string `json:"password"`
	Addr     string `json:"addr"`
	DB       int    `json:"db"`

	//sesion max age, like http cookie max-age
	MaxAge int `json:"maxage"`

	//name registered for codec
	//if no name supplied, use default GobCodec for session encode/decode
	CodecName string `json:"codec"`

	//max idle connection for remote redis
	MaxIdle int `json:"maxidle"`
}

type Session

type Session struct {
	Values map[interface{}]interface{}

	MaxAge int
	// contains filtered or unexported fields
}

func NewSession

func NewSession(id string, store Store, maxAge int) *Session

func (*Session) Delete

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

delete value by key

func (*Session) Expire

func (s *Session) Expire(seconds int) error

set session expire time, it will be affected after save

func (*Session) Flush

func (s *Session) Flush() error

delete all data, delete session from store and regenerate id

func (*Session) Get

func (s *Session) Get(key interface{}) interface{}

get value by key, nil if key not exist

func (*Session) ID

func (s *Session) ID() string

session id

func (*Session) Save

func (s *Session) Save() error

save session to store

func (*Session) Set

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

set value by key

type Store

type Store interface {
	//get a session by id
	//if no session exist, regenerate another id to new a session
	Get(id string) (*Session, error)

	//delete session from store
	Delete(*Session) error

	//Save session to stroe
	Save(*Session) error
}

func Open

func Open(name string, jsonConfig json.RawMessage) (Store, error)

Jump to

Keyboard shortcuts

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