session

package
v0.0.0-...-c7a0b58 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BeforeRegenerateSession []func(http.ResponseWriter, *http.Request)

BeforeRegenerateSession is a list of functions that are called before a session is regenerated.

View Source
var MockStoreContextKey = mockStoreContextKeyStruct{}

Functions

This section is empty.

Types

type DBProvider

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

DBProvider represents a DB session provider implementation.

func (*DBProvider) Count

func (p *DBProvider) Count() int

Count counts and returns number of sessions.

func (*DBProvider) Destroy

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

Destroy deletes a session by session ID.

func (*DBProvider) Exist

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

Exist returns true if session with given ID exists.

func (*DBProvider) GC

func (p *DBProvider) GC()

GC calls GC to clean expired sessions.

func (*DBProvider) Init

func (p *DBProvider) Init(maxLifetime int64, connStr string) error

Init initializes DB session provider. connStr: username:password@protocol(address)/dbname?param=value

func (*DBProvider) Read

func (p *DBProvider) Read(sid string) (session.RawStore, error)

Read returns raw session store by session ID.

func (*DBProvider) Regenerate

func (p *DBProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error)

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

type DBStore

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

DBStore represents a session store implementation based on the DB.

func NewDBStore

func NewDBStore(sid string, kv map[any]any) *DBStore

NewDBStore creates and returns a DB session store.

func (*DBStore) Delete

func (s *DBStore) Delete(key any) error

Delete delete a key from session.

func (*DBStore) Flush

func (s *DBStore) Flush() error

Flush deletes all session data.

func (*DBStore) Get

func (s *DBStore) Get(key any) any

Get gets value by given key in session.

func (*DBStore) ID

func (s *DBStore) ID() string

ID returns current session ID.

func (*DBStore) Release

func (s *DBStore) Release() error

Release releases resource and save data to provider.

func (*DBStore) Set

func (s *DBStore) Set(key, val any) error

Set sets value to given key in session.

type MockStore

type MockStore struct {
	*session.MemStore
}

func NewMockStore

func NewMockStore(sid string) *MockStore

func (*MockStore) Destroy

func (m *MockStore) Destroy(writer http.ResponseWriter, request *http.Request) error

type RedisProvider

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

RedisProvider represents a redis session provider implementation.

func (*RedisProvider) Count

func (p *RedisProvider) Count() int

Count counts and returns number of sessions.

func (*RedisProvider) Destroy

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

Destroy deletes a session by session ID.

func (*RedisProvider) Exist

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

Exist returns true if session with given ID exists.

func (*RedisProvider) GC

func (*RedisProvider) GC()

GC calls GC to clean expired sessions.

func (*RedisProvider) Init

func (p *RedisProvider) Init(maxlifetime int64, configs string) (err error)

Init initializes redis session provider. configs: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180,prefix=session;

func (*RedisProvider) Read

func (p *RedisProvider) Read(sid string) (session.RawStore, error)

Read returns raw session store by session ID.

func (*RedisProvider) Regenerate

func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error)

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

type RedisStore

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

RedisStore represents a redis session store implementation.

func NewRedisStore

func NewRedisStore(c redis.UniversalClient, prefix, sid string, dur time.Duration, kv map[any]any) *RedisStore

NewRedisStore creates and returns a redis session store.

func (*RedisStore) Delete

func (s *RedisStore) Delete(key any) error

Delete delete a key from session.

func (*RedisStore) Flush

func (s *RedisStore) Flush() error

Flush deletes all session data.

func (*RedisStore) Get

func (s *RedisStore) Get(key any) any

Get gets value by given key in session.

func (*RedisStore) ID

func (s *RedisStore) ID() string

ID returns current session ID.

func (*RedisStore) Release

func (s *RedisStore) Release() error

Release releases resource and save data to provider.

func (*RedisStore) Set

func (s *RedisStore) Set(key, val any) error

Set sets value to given key in session.

type Store

type Store interface {
	Get(any) any
	Set(any, any) error
	Delete(any) error
	ID() string
	Release() error
	Flush() error
	Destroy(http.ResponseWriter, *http.Request) error
}

Store represents a session store

func GetContextSession

func GetContextSession(req *http.Request) Store

func RegenerateSession

func RegenerateSession(resp http.ResponseWriter, req *http.Request) (Store, error)

RegenerateSession regenerates the underlying session and returns the new store

type VirtualSessionProvider

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

VirtualSessionProvider represents a shadowed session provider implementation.

func (*VirtualSessionProvider) Count

func (o *VirtualSessionProvider) Count() int

Count counts and returns number of sessions.

func (*VirtualSessionProvider) Destroy

func (o *VirtualSessionProvider) Destroy(sid string) error

Destroy deletes a session by session ID.

func (*VirtualSessionProvider) Exist

func (o *VirtualSessionProvider) Exist(sid string) bool

Exist returns true if session with given ID exists.

func (*VirtualSessionProvider) GC

func (o *VirtualSessionProvider) GC()

GC calls GC to clean expired sessions.

func (*VirtualSessionProvider) Init

func (o *VirtualSessionProvider) Init(gclifetime int64, config string) error

Init initializes the cookie session provider with given root path.

func (*VirtualSessionProvider) Read

Read returns raw session store by session ID.

func (*VirtualSessionProvider) Regenerate

func (o *VirtualSessionProvider) Regenerate(oldsid, sid string) (session.RawStore, error)

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

type VirtualStore

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

VirtualStore represents a virtual session store implementation.

func NewVirtualStore

func NewVirtualStore(p *VirtualSessionProvider, sid string, kv map[any]any) *VirtualStore

NewVirtualStore creates and returns a virtual session store.

func (*VirtualStore) Delete

func (s *VirtualStore) Delete(key any) error

Delete delete a key from session.

func (*VirtualStore) Flush

func (s *VirtualStore) Flush() error

Flush deletes all session data.

func (*VirtualStore) Get

func (s *VirtualStore) Get(key any) any

Get gets value by given key in session.

func (*VirtualStore) ID

func (s *VirtualStore) ID() string

ID returns current session ID.

func (*VirtualStore) Release

func (s *VirtualStore) Release() error

Release releases resource and save data to provider.

func (*VirtualStore) Set

func (s *VirtualStore) Set(key, val any) error

Set sets value to given key in session.

Jump to

Keyboard shortcuts

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