rethinkstore

package module
v0.0.0-...-614f6ea Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2016 License: MIT Imports: 10 Imported by: 4

README

rethinkstore Build Status

A session store backend for gorilla/sessions - src using Rethink.

Requirements

Depends on the gorethink library.

Installation

go get github.com/boj/rethinkstore

Documentation

Available on godoc.org.

See http://www.gorillatoolkit.org/pkg/sessions for full documentation on underlying interface.

Example
// Fetch new store.
store, err := NewRethinkStore("127.0.0.1:28015",
                              "my-db",
                              "my-session-table",
                              5 /*MaxIdle*/,
                              5 /*MaxOpen*/,
                              []byte("secret-key"))
if err != nil {
    panic(err)
}
defer store.Close()

// Get a session.
session, err := store.Get(req, "session-key")
if err != nil {
    log.Error(err.Error())
}

// Add a value.
session.Values["foo"] = "bar"

// Save.
if err = sessions.Save(req, rsp); err != nil {
    t.Fatalf("Error saving session: %v", err)
}

// Delete session, but not from the store
session.Options.MaxAge = -1
if err = sessions.Save(req, rsp); err != nil {
    t.Fatalf("Error saving session: %v", err)
}

// Delete expired data. Call this function periodically
session.Options.MaxAge = -1
if err = store.DeleteExpired(); err != nil {
    t.Fatalf("Error saving session: %v", err)
}


Documentation

Overview

Package rethinkstore is a session store backend for gorilla/sessions using Rethinkdb.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoDatabase = errors.New("no databases available")

Functions

This section is empty.

Types

type RethinkSession

type RethinkSession struct {
	Id      string    `gorethink:"id"`
	Expires time.Time `gorethink:"expires"`
	Session []byte    `gorethink:"session"`
}

type RethinkStore

type RethinkStore struct {
	Rethink       *r.Session           // rethink session
	Table         string               // table to store sessions in
	Codecs        []securecookie.Codec // session codecs
	Options       *sessions.Options    // default configuration
	DefaultMaxAge int                  // default TTL for a MaxAge == 0 session
}

RethinkStore stores sessions in a rethinkdb backend.

Example
// RethinkStore
store, err := NewRethinkStore("127.0.0.1:28015", TestDatabase, TestTable, 5, 5, []byte("secret-key"))
if err != nil {
	panic(err)
}
defer store.Close()
Output:

func NewRethinkStore

func NewRethinkStore(addr, db, table string, idle, open int, keyPairs ...[]byte) (*RethinkStore, error)

NewRethinkStore returns a new RethinkStore.

Takes in the database address, database name, session table, max idle connections, max open connections, and session key pairs.

func (*RethinkStore) Close

func (s *RethinkStore) Close()

Close closes the underlying Rethink Client.

func (*RethinkStore) Count

func (s *RethinkStore) Count() (uint, error)

func (*RethinkStore) DeleteExpired

func (s *RethinkStore) DeleteExpired() error

Deletes expired entries

func (*RethinkStore) Get

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

Get returns a session for the given name after adding it to the registry.

func (*RethinkStore) MaxAge

func (s *RethinkStore) MaxAge(age int)

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 (*RethinkStore) New

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

New returns a session for the given name without adding it to the registry.

func (*RethinkStore) Save

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

Save adds a single session to the response.

Jump to

Keyboard shortcuts

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