session: gitea.com/macaron/session Index | Files | Directories

package session

import "gitea.com/macaron/session"

Package session a middleware that provides the session management of Macaron.

Index

Package Files

file.go flash.go memory.go session.go utils.go

func DecodeGob Uses

func DecodeGob(encoded []byte) (out map[interface{}]interface{}, err error)

func EncodeGob Uses

func EncodeGob(obj map[interface{}]interface{}) ([]byte, error)

func Register Uses

func Register(name string, provider Provider)

Register registers a provider.

func Sessioner Uses

func Sessioner(options ...Options) macaron.Handler

Sessioner is a middleware that maps a session.SessionStore service into the Macaron handler chain. An single variadic session.Options struct can be optionally provided to configure.

func Version Uses

func Version() string

type FileProvider Uses

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

FileProvider represents a file session provider implementation.

func (*FileProvider) Count Uses

func (p *FileProvider) Count() int

Count counts and returns number of sessions.

func (*FileProvider) Destroy Uses

func (p *FileProvider) Destroy(sid string) error

Destroy deletes a session by session ID.

func (*FileProvider) Exist Uses

func (p *FileProvider) Exist(sid string) bool

Exist returns true if session with given ID exists.

func (*FileProvider) GC Uses

func (p *FileProvider) GC()

GC calls GC to clean expired sessions.

func (*FileProvider) Init Uses

func (p *FileProvider) Init(maxlifetime int64, rootPath string) error

Init initializes file session provider with given root path.

func (*FileProvider) Read Uses

func (p *FileProvider) Read(sid string) (_ RawStore, err error)

Read returns raw session store by session ID.

func (*FileProvider) Regenerate Uses

func (p *FileProvider) Regenerate(oldsid, sid string) (_ RawStore, err error)

Regenerate regenerates a session store from old session ID to new one.

type FileStore Uses

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

FileStore represents a file session store implementation.

func NewFileStore Uses

func NewFileStore(p *FileProvider, sid string, kv map[interface{}]interface{}) *FileStore

NewFileStore creates and returns a file session store.

func (*FileStore) Delete Uses

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

Delete delete a key from session.

func (*FileStore) Flush Uses

func (s *FileStore) Flush() error

Flush deletes all session data.

func (*FileStore) Get Uses

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

Get gets value by given key in session.

func (*FileStore) ID Uses

func (s *FileStore) ID() string

ID returns current session ID.

func (*FileStore) Release Uses

func (s *FileStore) Release() error

Release releases resource and save data to provider.

func (*FileStore) Set Uses

func (s *FileStore) Set(key, val interface{}) error

Set sets value to given key in session.

type Flash Uses

type Flash struct {
    url.Values
    ErrorMsg, WarningMsg, InfoMsg, SuccessMsg string
    // contains filtered or unexported fields
}

func (*Flash) Error Uses

func (f *Flash) Error(msg string, current ...bool)

func (*Flash) Info Uses

func (f *Flash) Info(msg string, current ...bool)

func (*Flash) Success Uses

func (f *Flash) Success(msg string, current ...bool)

func (*Flash) Warning Uses

func (f *Flash) Warning(msg string, current ...bool)

type Manager Uses

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

Manager represents a struct that contains session provider and its configuration.

func NewManager Uses

func NewManager(name string, opt Options) (*Manager, error)

NewManager creates and returns a new session manager by given provider name and configuration. It panics when given provider isn't registered.

func (*Manager) Count Uses

func (m *Manager) Count() int

Count counts and returns number of sessions.

func (*Manager) Destroy Uses

func (m *Manager) Destroy(ctx *macaron.Context) error

Destroy deletes a session by given ID.

func (*Manager) GC Uses

func (m *Manager) GC()

GC starts GC job in a certain period.

func (*Manager) Read Uses

func (m *Manager) Read(sid string) (RawStore, error)

Read returns raw session store by session ID.

func (*Manager) RegenerateId Uses

func (m *Manager) RegenerateId(ctx *macaron.Context) (sess RawStore, err error)

RegenerateId regenerates a session store from old session ID to new one.

func (*Manager) SetSecure Uses

func (m *Manager) SetSecure(secure bool)

SetSecure indicates whether to set cookie with HTTPS or not.

func (*Manager) Start Uses

func (m *Manager) Start(ctx *macaron.Context) (RawStore, error)

Start starts a session by generating new one or retrieve existence one by reading session ID from HTTP request if it's valid.

type MemProvider Uses

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

MemProvider represents a in-memory session provider implementation.

func (*MemProvider) Count Uses

func (p *MemProvider) Count() int

Count counts and returns number of sessions.

func (*MemProvider) Destroy Uses

func (p *MemProvider) Destroy(sid string) error

Destroy deletes a session by session ID.

func (*MemProvider) Exist Uses

func (p *MemProvider) Exist(sid string) bool

Exist returns true if session with given ID exists.

func (*MemProvider) GC Uses

func (p *MemProvider) GC()

GC calls GC to clean expired sessions.

func (*MemProvider) Init Uses

func (p *MemProvider) Init(maxLifetime int64, _ string) error

Init initializes memory session provider.

func (*MemProvider) Read Uses

func (p *MemProvider) Read(sid string) (_ RawStore, err error)

Read returns raw session store by session ID.

func (*MemProvider) Regenerate Uses

func (p *MemProvider) Regenerate(oldsid, sid string) (RawStore, error)

Regenerate regenerates a session store from old session ID to new one.

type MemStore Uses

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

MemStore represents a in-memory session store implementation.

func NewMemStore Uses

func NewMemStore(sid string) *MemStore

NewMemStore creates and returns a memory session store.

func (*MemStore) Delete Uses

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

Delete deletes a key from session.

func (*MemStore) Flush Uses

func (s *MemStore) Flush() error

Flush deletes all session data.

func (*MemStore) Get Uses

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

Get gets value by given key in session.

func (*MemStore) ID Uses

func (s *MemStore) ID() string

ID returns current session ID.

func (*MemStore) Release Uses

func (_ *MemStore) Release() error

Release releases resource and save data to provider.

func (*MemStore) Set Uses

func (s *MemStore) Set(key, val interface{}) error

Set sets value to given key in session.

type Options Uses

type Options struct {
    // Name of provider. Default is "memory".
    Provider string
    // Provider configuration, it's corresponding to provider.
    ProviderConfig string
    // Cookie name to save session ID. Default is "MacaronSession".
    CookieName string
    // Cookie path to store. Default is "/".
    CookiePath string
    // GC interval time in seconds. Default is 3600.
    Gclifetime int64
    // Max life time in seconds. Default is whatever GC interval time is.
    Maxlifetime int64
    // Use HTTPS only. Default is false.
    Secure bool
    // Cookie life time. Default is 0.
    CookieLifeTime int
    // Cookie domain name. Default is empty.
    Domain string
    // Session ID length. Default is 16.
    IDLength int
    // Configuration section name. Default is "session".
    Section string
    // Ignore release for websocket. Default is false.
    IgnoreReleaseForWebSocket bool
}

Options represents a struct for specifying configuration options for the session middleware.

type Provider Uses

type Provider interface {
    // Init initializes session provider.
    Init(gclifetime int64, config string) error
    // Read returns raw session store by session ID.
    Read(sid string) (RawStore, error)
    // Exist returns true if session with given ID exists.
    Exist(sid string) bool
    // Destroy deletes a session by session ID.
    Destroy(sid string) error
    // Regenerate regenerates a session store from old session ID to new one.
    Regenerate(oldsid, sid string) (RawStore, error)
    // Count counts and returns number of sessions.
    Count() int
    // GC calls GC to clean expired sessions.
    GC()
}

Provider is the interface that provides session manipulations.

type RawStore Uses

type RawStore interface {
    // Set sets value to given key in session.
    Set(interface{}, interface{}) error
    // Get gets value by given key in session.
    Get(interface{}) interface{}
    // Delete deletes a key from session.
    Delete(interface{}) error
    // ID returns current session ID.
    ID() string
    // Release releases session resource and save data to provider.
    Release() error
    // Flush deletes all session data.
    Flush() error
}

RawStore is the interface that operates the session data.

type Store Uses

type Store interface {
    RawStore
    // Read returns raw session store by session ID.
    Read(string) (RawStore, error)
    // Destroy deletes a session.
    Destroy(*macaron.Context) error
    // RegenerateId regenerates a session store from old session ID to new one.
    RegenerateId(*macaron.Context) (RawStore, error)
    // Count counts and returns number of sessions.
    Count() int
    // GC calls GC to clean expired sessions.
    GC()
}

Store is the interface that contains all data for one session process with specific ID.

Directories

PathSynopsis
couchbase
ledis
memcache
mysql
nodb
postgres
redis

Package session imports 19 packages (graph) and is imported by 20 packages. Updated 2019-09-15. Refresh now. Tools for package owners.