Package sqlsess

import "github.com/BurntSushi/sqlsess"
Overview
Index

Overview ▾

Variables

var (
    SessionLastUpdated = "__sess_last_updated"
    CookieIdName       = "sess_sessionid"
    SqlTableName       = "sess_session"
    SqlCreateSession   = `
    CREATE TABLE IF NOT EXISTS ` + SqlTableName + ` (
        id BYTEA NOT NULL,
        name VARCHAR (255) NOT NULL,
        key TEXT NOT NULL,
        value TEXT NOT NULL,
        PRIMARY KEY (id, name, key)
    )
    `
)

func Lock

func Lock(sess *sessions.Session)

func RLock

func RLock(sess *sessions.Session)

func RUnlock

func RUnlock(sess *sessions.Session)

func Unlock

func Unlock(sess *sessions.Session)

type Store

type Store struct {
    *sql.DB
    // contains filtered or unexported fields
}

func Open

func Open(db *sql.DB) (*Store, error)

func (*Store) Clean

func (s *Store) Clean(inactive time.Duration) error

func (*Store) Delete

func (s *Store) Delete(sess *sessions.Session) error

func (*Store) Get

func (s *Store) Get(r *http.Request, name string) (*sessions.Session, error)

func (*Store) New

func (s *Store) New(r *http.Request, name string) (*sessions.Session, error)

func (*Store) Save

func (s *Store) Save(
    r *http.Request,
    w http.ResponseWriter,
    sess *sessions.Session,
) error

func (*Store) SetKeys

func (s *Store) SetKeys(hash, block []byte)

SetKeys sets the hash and block keys used to read and write the session cookie. A hash key is required and is used to to authenticate a cookie value using HMAC. It's recommend to be 32 or 64 bytes.

A block key is optional and is used to encrypt the cookie value. If it's set to nil, then encryption will not be used. This package uses AES, so the block key must have length 16, 24 or 32 bytes corresponding to AES-128, AES-192 or AES-256. If the block key violates these constraints, SetKeys will panic.

This method is exposed so that multiple instantiations of session stores can share the same cookie. This particularly useful if you want to be able to restart your web server without invalidating existing user sessions.

If this method is not called, then a fresh set of keys is created automatically, but will invalidate all existing user sessions.