Fork of pgstore using sqlx instead of sql.
Go to file
Anton Lindstrom d42994de5c Refactor parts of the code and add more tests
This is a refactor of parts of the code, some minor things such as adding
punctuation in the end of sentences and making the code a bit easier to read.

More tests has been added in the form of gometalinter which checks the code
health, style and spelling errors. The flaky cleanup test should also be fixed
with this commit.
2016-07-21 20:02:52 +00:00
.travis.yml Refactor parts of the code and add more tests 2016-07-21 20:02:52 +00:00
Makefile Refactor parts of the code and add more tests 2016-07-21 20:02:52 +00:00
README.md Add breaking changes note to README 2016-07-19 21:21:08 +02:00
cleanup.go Refactor parts of the code and add more tests 2016-07-21 20:02:52 +00:00
cleanup_test.go Refactor parts of the code and add more tests 2016-07-21 20:02:52 +00:00
pgstore.go Refactor parts of the code and add more tests 2016-07-21 20:02:52 +00:00
pgstore_test.go Refactor parts of the code and add more tests 2016-07-21 20:02:52 +00: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, err := NewPGStore("postgres://user:password@127.0.0.1:5432/database?sslmode=verify-full", []byte("secret-key"))
if err != nil {
    log.Error(err.Error())
}
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)
}

Breaking changes

  • 2016-07-19 - NewPGStore and NewPGStoreFromPool now returns (*PGStore, error)

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.