README
¶
rethinkstore
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, 5, []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.
session.Options.MaxAge = -1
if err = sessions.Save(req, rsp); err != nil {
t.Fatalf("Error saving session: %v", err)
}
Documentation
¶
Overview ¶
Package rethinkstore is a session store backend for gorilla/sessions using Rethinkdb.
Index ¶
- Variables
- type RethinkSession
- type RethinkStore
- func (s *RethinkStore) Close()
- func (s *RethinkStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *RethinkStore) MaxAge(age int)
- func (s *RethinkStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (s *RethinkStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoDatabase = errors.New("no databases available")
Functions ¶
This section is empty.
Types ¶
type RethinkSession ¶
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 ¶
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) Get ¶
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 ¶
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.