A session store backend for gorilla/sessions - src.
make get-deps
Available on godoc.org.
See http://www.gorillatoolkit.org/pkg/sessions for full documentation on underlying interface.
// Fetch new store.
store := NewPGStore("postgres://user:[email protected]:5432/database?sslmode=verify-full", []byte("secret-key"))
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)
}
I've stolen, borrowed and gotten inspiration from the other backends available:
Thank you all for sharing your code!
What makes this backend different is that it's for Postgresql and uses the fine datamapper Gorp. Make sure you use a somewhat new codebase of Gorp as it now defaults to text for strings when it used to default to varchar 255. Varchar 255 is unfortunately too small.