项目作者: KaiserWerk

项目描述 :
A small Go library to manage in-memory sessions, variables and associated session cookies.
高级语言: Go
项目地址: git://github.com/KaiserWerk/sessionstore.git
创建时间: 2020-08-12T01:15:31Z
项目社区:https://github.com/KaiserWerk/sessionstore

开源协议:

下载


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:

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

Session

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

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

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

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

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

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

Session Variables/Values

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

  1. sess.SetVar("key", "value")
  2. val, exists := sess.GetVar("key")

Cookies

coming soon