Documentation ¶
Overview ¶
Package sqlsessionstores provides a session store backed by an SQL database. Supported dialects are PostgreSQL and SQLite.
You have to import the appropriate SQL driver yourself, e.g.:
import _ "github.com/lib/pq" // for PostgreSQL, or: import _ "github.com/mattn/go-sqlite3" // for SQLite
Index ¶
- Constants
- Variables
- type AuthOptions
- type Store
- func (s *Store) Delete(writer http.ResponseWriter, sessionID string) error
- func (s *Store) DeleteMulti(filter *sessions.Filter) error
- func (s *Store) Get(writer http.ResponseWriter, request *http.Request) (sessions.Session, error)
- func (s *Store) GetMulti(filter *sessions.Filter) ([]sessions.Session, error)
- func (s *Store) Save(writer http.ResponseWriter, session sessions.Session) error
- func (s *Store) SaveMulti(sessions []sessions.Session) (e error)
Constants ¶
const ( // AuthMethodCookie means the session ID is passed via cookie. AuthMethodCookie = authMethod("cookie") // AuthMethodHeader means the session ID is passed via request header. AuthMethodHeader = authMethod("header") )
const ( DialectPostgreSQL = "postgresql" DialectSQLite = "sqlite" )
Supported SQL dialects.
Variables ¶
var KeyUserID = "user.id"
KeyUserID is the key used to retrieve the user ID from session.Values and store it in an indexed table column. This makes it possible to delete all sessions of a particular user.
Functions ¶
This section is empty.
Types ¶
type AuthOptions ¶
type AuthOptions struct { AuthMethod authMethod // Cookie… fields are used when setting the cookie. CookieDomain string CookieName string CookiePath string // HeaderName is the name of the request header that is used to pass the // session ID. HeaderName string }
AuthOptions is the authentification configuration for the store. If AuthMethod is AuthMethodCookie, Cookie… options are used. If AuthMethod is AuthMethodHeader, Header… options are used.
type Store ¶
type Store struct { // Authentication options. AuthOptions AuthOptions // DB is the database in which the sessions table resides. DB *sql.DB // SQL dialect to use. Dialect string // Expiration is the duration after which sessions expire. Expiration time.Duration // Strength is the number of bytes to use for generating a session ID. The // higher the number, the more secure the session ID. Strength int // TableName is the name of the sessions table. TableName string }
Store contains information about the session store.
func New ¶
New returns a new Store. If a table with the specified name does not exist, it is created.
func (*Store) Delete ¶
func (s *Store) Delete(writer http.ResponseWriter, sessionID string) error
Delete deletes a session from the store.
func (*Store) DeleteMulti ¶
DeleteMulti deletes sessions from the store that match the criteria specified in filter. If no criterion is specified, all sessions are deleted.
func (*Store) Get ¶
Get gets a session from the store using the session ID passed with the request via cookie or header (depending on s.AuthOptions.AuthMethod).
func (*Store) GetMulti ¶
GetMulti gets sessions from the store that match the criteria specified in filter.