Fork of pgstore using sqlx instead of sql.
Go to file
Your Name cb19905ec5 Rename package and update documentation 2018-11-23 20:10:42 +00:00
examples Rename package and update documentation 2018-11-23 20:10:42 +00:00
.travis.yml Fix issues with linter and drop 1.5 CI tests 2017-03-13 12:06:53 +00:00
LICENSE Add MIT license file 2017-06-04 07:14:07 +00:00
Makefile Fix issues with linter and drop 1.5 CI tests 2017-03-13 12:06:53 +00:00
README.md Rename package and update documentation 2018-11-23 20:10:42 +00:00
cleanup.go Remove the Gorp dependency 2016-08-11 15:06:09 -04:00
cleanup_test.go Remove the Gorp dependency 2016-08-11 15:06:09 -04:00
pgstore.go Rename package and update documentation 2018-11-23 20:10:42 +00:00
pgstore_test.go Rename package and update documentation 2018-11-23 20:10:42 +00:00

README.md

pgstorex

A session store backend for gorilla/sessions - src.

100% based on pgstore

Installation

make get-deps

Documentation

Available on godoc.org.

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

Example

package examples

import (
	"log"
	"net/http"
	"time"

	"gitto.work/shortcut/pgstorex"
)

// ExampleHandler is an example that displays the usage of PGStore.
func ExampleHandler(w http.ResponseWriter, r *http.Request) {
	// Fetch new store.
	store, err := pgstorex.NewPGStore("postgres://user:password@127.0.0.1:5432/database?sslmode=verify-full", []byte("secret-key"))
	if err != nil {
		log.Fatalf(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(r, "session-key")
	if err != nil {
		log.Fatalf(err.Error())
	}

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

	// Save.
	if err = session.Save(r, w); err != nil {
		log.Fatalf("Error saving session: %v", err)
	}

	// Delete session.
	session.Options.MaxAge = -1
	if err = session.Save(r, w); err != nil {
		log.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.

We've recently refactored this backend to use the standard database/sql driver instead of Gorp. This removes a dependency and makes this package very lightweight and makes database interactions very transparent. Lastly, from the standpoint of unit testing where you want to mock the database layer instead of requiring a real database, you can now easily use a package like go-SQLMock to do just that.