Skip to content

A PostgreSQL backend for storing Gorilla Web Toolkit sessions.

Notifications You must be signed in to change notification settings

philboltt/postgrestore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

postgrestore

build status

A PostgreSQL store for gorilla/sessions - src.

Dependencies

Installation

go get github.com/philboltt/postgrestore

Documentation

Available on godoc.org.

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

Example

// Fetch new store (path="/", MaxAge=30days, i.e. 60sec*60min*24hrs*30days)
store := NewPostgreSQLStore("postgres://user:password@server:port/database?sslmode=disable", "/", 60*60*24*30, []byte("secret-key"))
defer store.Close()

// Get a session.
session, err = store.Get(req, "mySessionName")
if err != nil {
    log.Error(err.Error())
}

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

// Save - creates a new record in the database if none exists, or updates an existing one.
if err = sessions.Save(req, rsp); err != nil {
    t.Fatalf("Error saving session: %v", err)
}

// Delete - removes session record from the database and clears the session ID from the client cookie.
store.Delete(resp, session)

See the tests for more examples.

Thanks

This package is largely a rehash of the code and ideas from these fine repos:

Thank you all for sharing your code!

About

A PostgreSQL backend for storing Gorilla Web Toolkit sessions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages