Fork of pgstore using sqlx instead of sql.
Go to file
Anton Lindström 4cff112644 Merge pull request #8 from elithrar/max-age-fix
Provide method to set MaxAge on underlying cookies.
2015-08-11 15:41:50 +02:00
.drone.yml fix drone testing 2014-06-10 15:20:15 +00:00
Makefile add step build and test to Makefile 2014-05-20 06:02:59 +00:00
README.md feature: expired sessions can be deleted via a background goroutine. 2015-07-11 11:56:04 +08:00
cleanup.go feature: expired sessions can be deleted via a background goroutine. 2015-07-11 11:56:04 +08:00
cleanup_test.go feature: expired sessions can be deleted via a background goroutine. 2015-07-11 11:56:04 +08:00
pgstore.go Provide method to set MaxAge on underlying cookies. 2015-08-11 20:13:41 +08:00
pgstore_test.go Added MaxLength support port of: https://github.com/boj/redistore/pull/5 2015-07-15 15:08:34 +01:00

README.md

pgstore

A session store backend for gorilla/sessions - src.

Installation

make get-deps

Documentation

Available on godoc.org.

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

Example

// Fetch new store.
store := NewPGStore("postgres://user:password@127.0.0.1:5432/database?sslmode=verify-full", []byte("secret-key"))
defer store.Close()
// Run a background goroutine to clean up expired sessions from the database.
defer store.StopCleanup(store.Cleanup(time.Minute * 5))

// 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)
}

Thanks

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.