Documentation

Index

Constants

View Source
const DefaultFirestoreCollection = "session"
View Source
const DefaultMySQLTableName = "session"
View Source
const DefaultRedisDatabase = 0
View Source
const (
	DefaultSessionExpiration = 1200
)
View Source
const (
	ErrorSessionDoesNotExist = "ERR_SESSION_EXISTS"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileProvider

type FileProvider struct {
	Path string
}

func (*FileProvider) Destroy

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

func (*FileProvider) GarbageCollect

func (p *FileProvider) GarbageCollect()

func (*FileProvider) Read

func (p *FileProvider) Read(sid string) (*Session, error)

func (*FileProvider) Save

func (p *FileProvider) Save(session *Session) error

type FirestoreProvider

type FirestoreProvider struct {
	Context        context.Context
	Client         *firestore.Client
	Collection     *firestore.CollectionRef
	CollectionName string
}

func NewFirestoreProvider

func NewFirestoreProvider(ctx context.Context, client *firestore.Client, collectionName string) *FirestoreProvider

func (*FirestoreProvider) Destroy

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

func (*FirestoreProvider) GarbageCollect

func (p *FirestoreProvider) GarbageCollect()

func (*FirestoreProvider) Read

func (p *FirestoreProvider) Read(sid string) (*Session, error)

func (*FirestoreProvider) Save

func (p *FirestoreProvider) Save(session *Session) error

type MemcacheProvider

type MemcacheProvider struct {
	Servers []string
}

func (*MemcacheProvider) Destroy

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

func (*MemcacheProvider) GarbageCollect

func (p *MemcacheProvider) GarbageCollect()

func (*MemcacheProvider) Read

func (p *MemcacheProvider) Read(sid string) (*Session, error)

func (*MemcacheProvider) Save

func (p *MemcacheProvider) Save(session *Session) error

type MemoryProvider

type MemoryProvider struct {
	Store map[string]*Session
}

func NewMemoryProvider

func NewMemoryProvider() *MemoryProvider

func (*MemoryProvider) Destroy

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

func (*MemoryProvider) GarbageCollect

func (p *MemoryProvider) GarbageCollect()

func (*MemoryProvider) Read

func (p *MemoryProvider) Read(sid string) (*Session, error)

func (*MemoryProvider) Save

func (p *MemoryProvider) Save(sess *Session) error

type MySQLProvider

type MySQLProvider struct {
	*sql.DB
	Table string
}

func NewMySQLProvider

func NewMySQLProvider(db *sql.DB, table string) (*MySQLProvider, error)

func (*MySQLProvider) Destroy

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

func (*MySQLProvider) GarbageCollect

func (p *MySQLProvider) GarbageCollect()

func (*MySQLProvider) MySQLSetupCheck

func (p *MySQLProvider) MySQLSetupCheck() error

func (*MySQLProvider) Read

func (p *MySQLProvider) Read(sid string) (*Session, error)

func (*MySQLProvider) Save

func (p *MySQLProvider) Save(session *Session) error

type Provider

type Provider interface {
	Read(sid string) (*Session, error)
	Save(session *Session) error
	Destroy(sid string) error
	GarbageCollect()
}

type RedisProvider

type RedisProvider struct {
	// Servers []string
	Client  *redis.Client
	Options *redis.Options
}

func NewRedisProvider

func NewRedisProvider(server, password string, database int) (*RedisProvider, error)

func (*RedisProvider) CalcExpiration

func (p *RedisProvider) CalcExpiration(s *Session) time.Duration

func (*RedisProvider) Destroy

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

func (*RedisProvider) GarbageCollect

func (p *RedisProvider) GarbageCollect()

func (*RedisProvider) Read

func (p *RedisProvider) Read(sid string) (*Session, error)

func (*RedisProvider) RedisInit

func (p *RedisProvider) RedisInit()

func (*RedisProvider) Save

func (p *RedisProvider) Save(session *Session) error

type Session

type Session struct {
	UUID   string                 `json:"uuid"`
	Lock   sync.Mutex             `json:"-"`
	Data   map[string]interface{} `json:"data"`
	Expire time.Time              `json:"expire"`
}

func NewSession

func NewSession() *Session

func NewSessionWithId

func NewSessionWithId(sid string) *Session

func (*Session) Set

func (sess *Session) Set(k string, v interface{})

func (*Session) SetData

func (sess *Session) SetData(m map[string]interface{})

func (*Session) SetExpire

func (sess *Session) SetExpire(exp time.Time)