KaiserWerk / sessionstore

A small Go library to manage in-memory sessions, variables and associated session cookies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sessionstore

Go Reference

This is a pure Go session store implementation. A session manager is use to create and remove sessions, add, edit and remove values bound to a session. This can be used to contextualize sessions, e.g. for logically separating user login and admin login or shoping carts or ....

Prerequisites

  • You should have a basic knowledge of how sessions and cookies work.

Usage

SessionManager

As initialization, create a new SessionManager with a supplied session cookie name:

var sessMgr *sessionstore.SessionManager = sessionstore.NewManager("MY_SESSION_NAME")

Session

Then, you can create a Session with a supplied validity, e.g. 30 days:

sess, err := sessMgr.CreateSession(time.Now().Add(30 * 24 * time.Hour))

Retrieve a Session by ID (typically obtained from a session cookie):

sess, err := sessMgr.GetSession("123abc")

Remove a Session by ID (when a user logs out):

err := sessMgr.RemoveSession("123abc")

Session Variables/Values

Add or set a value to a session (not SessionManager!) and get it:

sess.SetVar("key", "value")

val, exists := sess.GetVar("key")

Cookies

coming soon


About

A small Go library to manage in-memory sessions, variables and associated session cookies.

License:MIT License


Languages

Language:Go 100.0%