session

package module
v0.0.0-...-3115f8d Latest Latest
Warning

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

Go to latest
Published: May 26, 2017 License: BSD-3-Clause Imports: 11 Imported by: 11 modules, 14 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

session CircleCI

Session is a session middleware for Tango.

Backend Supports

Currently session support some backends below:

  • Memory - memory as a session store, this is the default store
  • nodb - nodb as a session store
  • redis - redis server as a session store
  • ledis - ledis server as a session store
  • ssdb - ssdb server as a session store

Installation

go get github.com/tango-contrib/session

Simple Example

package main

import (
    "github.com/lunny/tango"
    "github.com/tango-contrib/session"
)

type SessionAction struct {
    session.Session
}

func (a *SessionAction) Get() string {
    a.Session.Set("test", "1")
    return a.Session.Get("test").(string)
}

func main() {
    o := tango.Classic()
    o.Use(session.New(session.Options{
        MaxAge:time.Minute * 20,
        }))
    o.Get("/", new(SessionAction))
}

Getting Help

License

This project is under BSD License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	DefaultMaxAge        = 30 * time.Minute
	DefaultSessionIdName = "SESSIONID"
	DefaultCookiePath    = "/"
)

Variables

This section is empty.

Functions

func GenRandKey

func GenRandKey(strength int) []byte

Types

type CookieTracker

type CookieTracker struct {
	Name     string
	MaxAge   time.Duration
	Lock     sync.Mutex
	Secure   bool
	RootPath string
	Domain   string
}

CookieTracker provide sessionid from cookie

func NewCookieTracker

func NewCookieTracker(name string, maxAge time.Duration, secure bool, rootPath string) *CookieTracker

func (*CookieTracker) Clear

func (tracker *CookieTracker) Clear(rw http.ResponseWriter)

func (*CookieTracker) Get

func (tracker *CookieTracker) Get(req *http.Request) (Id, error)

func (*CookieTracker) Set

func (tracker *CookieTracker) Set(req *http.Request, rw http.ResponseWriter, id Id)

func (*CookieTracker) SetMaxAge

func (tracker *CookieTracker) SetMaxAge(maxAge time.Duration)

type CookieUrlTracker

type CookieUrlTracker struct {
	CookieTracker
}

func NewCookieUrlTracker

func NewCookieUrlTracker(name string, maxAge time.Duration, secure bool, rootPath string) *CookieUrlTracker

for SWFUpload ...

func (*CookieUrlTracker) Get

func (tracker *CookieUrlTracker) Get(req *http.Request) (Id, error)

type HeaderTracker

type HeaderTracker struct {
	Name string
}

func NewHeaderTracker

func NewHeaderTracker(name string) *HeaderTracker

func (*HeaderTracker) Clear

func (tracker *HeaderTracker) Clear(rw http.ResponseWriter)

func (*HeaderTracker) Get

func (tracker *HeaderTracker) Get(req *http.Request) (Id, error)

func (*HeaderTracker) Set

func (tracker *HeaderTracker) Set(req *http.Request, rw http.ResponseWriter, id Id)

func (*HeaderTracker) SetMaxAge

func (tracker *HeaderTracker) SetMaxAge(maxAge time.Duration)

type Id

type Id string

type IdGenerator

type IdGenerator interface {
	Gen(req *http.Request) Id
	IsValid(id Id) bool
}

type MemoryStore

type MemoryStore struct {
	GcInterval time.Duration
	// contains filtered or unexported fields
}

func NewMemoryStore

func NewMemoryStore(maxAge time.Duration) *MemoryStore

func (*MemoryStore) Add

func (store *MemoryStore) Add(id Id) bool

func (*MemoryStore) Clear

func (store *MemoryStore) Clear(id Id) bool

func (*MemoryStore) Del

func (store *MemoryStore) Del(id Id, key string) bool

func (*MemoryStore) Exist

func (store *MemoryStore) Exist(id Id) bool

func (*MemoryStore) Get

func (store *MemoryStore) Get(id Id, key string) interface{}

func (*MemoryStore) Run

func (store *MemoryStore) Run() error

func (*MemoryStore) Set

func (store *MemoryStore) Set(id Id, key string, value interface{}) error

func (*MemoryStore) SetIdMaxAge

func (store *MemoryStore) SetIdMaxAge(id Id, maxAge time.Duration)

func (*MemoryStore) SetMaxAge

func (store *MemoryStore) SetMaxAge(maxAge time.Duration)

type Options

type Options struct {
	MaxAge           time.Duration
	SessionIdName    string
	Store            Store
	Generator        IdGenerator
	Tracker          Tracker
	OnSessionNew     func(*Session)
	OnSessionRelease func(*Session)
}

type Session

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

func (*Session) Del

func (session *Session) Del(key string) bool

func (*Session) Get

func (session *Session) Get(key string) interface{}

func (*Session) GetSession

func (session *Session) GetSession() *Session

func (*Session) Id

func (session *Session) Id() Id

func (*Session) InitSession

func (session *Session) InitSession(manager *Sessions, req *http.Request, rw http.ResponseWriter) error

func (*Session) IsValid

func (session *Session) IsValid() bool

func (*Session) Release

func (session *Session) Release()

func (*Session) Sessions

func (session *Session) Sessions() *Sessions

func (*Session) Set

func (session *Session) Set(key string, value interface{})

func (*Session) SetId

func (session *Session) SetId(id Id)

func (*Session) SetMaxAge

func (session *Session) SetMaxAge(maxAge time.Duration)

type Sessioner

type Sessioner interface {
	GetSession() *Session
	InitSession(*Sessions, *http.Request, http.ResponseWriter) error
}

Sessioner Session interface

type Sessions

type Sessions struct {
	Options
}

func Default

func Default() *Sessions

func New

func New(opts ...Options) *Sessions

func NewWithTimeout

func NewWithTimeout(maxAge time.Duration) *Sessions

func (*Sessions) Exist

func (manager *Sessions) Exist(id Id) bool

func (*Sessions) Handle

func (itor *Sessions) Handle(ctx *tango.Context)

func (*Sessions) Invalidate

func (manager *Sessions) Invalidate(rw http.ResponseWriter, session *Session)

func (*Sessions) Run

func (manager *Sessions) Run() error

func (*Sessions) Session

func (manager *Sessions) Session(req *http.Request, rw http.ResponseWriter) *Session

func (*Sessions) SessionFromID

func (manager *Sessions) SessionFromID(id Id) *Session

func (*Sessions) SetIdMaxAge

func (manager *Sessions) SetIdMaxAge(id Id, maxAge time.Duration)

func (*Sessions) SetMaxAge

func (manager *Sessions) SetMaxAge(maxAge time.Duration)

type Sessionser

type Sessionser interface {
	SetSessions(*Sessions)
}

type Sha1Generator

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

func NewSha1Generator

func NewSha1Generator(hashKey string) *Sha1Generator

func (*Sha1Generator) Gen

func (gen *Sha1Generator) Gen(req *http.Request) Id

func (*Sha1Generator) IsValid

func (gen *Sha1Generator) IsValid(id Id) bool

type Store

type Store interface {
	Add(id Id) bool
	Exist(id Id) bool
	Clear(id Id) bool

	Get(id Id, key string) interface{}
	Set(id Id, key string, value interface{}) error
	Del(id Id, key string) bool

	SetMaxAge(maxAge time.Duration)
	SetIdMaxAge(id Id, maxAge time.Duration)

	Run() error
}

type Tracker

type Tracker interface {
	SetMaxAge(maxAge time.Duration)
	Get(req *http.Request) (Id, error)
	Set(req *http.Request, rw http.ResponseWriter, id Id)
	Clear(rw http.ResponseWriter)
}

Tracker provide and set sessionid

type UrlTracker

type UrlTracker struct {
	Key         string
	ReplaceLink bool
}

UrlTracker provide sessionid from url

func NewUrlTracker

func NewUrlTracker(key string, replaceLink bool) *UrlTracker

func (*UrlTracker) Clear

func (tracker *UrlTracker) Clear(rw http.ResponseWriter)

func (*UrlTracker) Get

func (tracker *UrlTracker) Get(req *http.Request) (Id, error)

func (*UrlTracker) Set

func (tracker *UrlTracker) Set(req *http.Request, rw http.ResponseWriter, id Id)

func (*UrlTracker) SetMaxAge

func (tracker *UrlTracker) SetMaxAge(maxAge time.Duration)

Jump to

Keyboard shortcuts

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