Documentation
¶
Overview ¶
Package bothold_store is a BotHold backend for gorilla sessions
Simplest form:
import (
bh "github.com/timshannon/bolthold"
bhs "github.com/jonhamm/bolthold_store"
)
func main() {
. . . .
var db *bothold.Store;
var store *bhs.Store
var err error
if db,err = bothold.Open(...); err != nil {
panic(err)
}
defer() db.Close()
if store,err := bhs.New(db, []byte("secret-hash-key")); err != nil {
panic(err)
}
All options:
store,err = bhs.NewSessionStore(
db,
[]byte("secret-hash-key"), // 32 or 64 bytes recommended, required
[]byte("secret-encryption-key")) // nil, 16, 24 or 32 bytes, optional
if err != nil {
panic(err)
}
// some more settings, see sessions.Options
store.SessionOpts.Secure = true
store.SessionOpts.HttpOnly = true
store.SessionOpts.MaxAge = 60 * 60 * 24 * 60
If you want periodic cleanup of expired sessions:
quit := make(chan struct{})
go store.PeriodicCleanup(1*time.Hour, quit)
For more information about the keys see https://github.com/gorilla/securecookie
For API to use in HTTP handlers see https://github.com/gorilla/sessions
Index ¶
- type BotholdSession
- type DB
- func (st *DB) Cleanup()
- func (st *DB) Get(r *http.Request, name string) (*sessions.Session, error)
- func (st *DB) MaxAge(age int)
- func (st *DB) MaxLength(l int)
- func (st *DB) New(r *http.Request, name string) (*sessions.Session, error)
- func (st *DB) PeriodicCleanup(interval time.Duration, quit <-chan struct{})
- func (st *DB) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BotholdSession ¶
type DB ¶
type DB struct {
Codecs []securecookie.Codec
SessionOpts *sessions.Options
// contains filtered or unexported fields
}
DB represent a bothold_store
func NewSessionStore ¶
/ NewSessionStore creates a new bothold_store session with options
func (*DB) MaxAge ¶
MaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.
func (*DB) MaxLength ¶
MaxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default is 4096 (default for securecookie)
func (*DB) PeriodicCleanup ¶
PeriodicCleanup runs Cleanup every interval. Close quit channel to stop.