Package Usage: go: github.com/icza/session
Package session provides an easy-to-use, extensible and secure HTTP session implementation and management.
This is "just" an HTTP session implementation and management, you can use it as-is, or with any existing Go web toolkits and frameworks.
Package documentation can be found and godoc.org:
https://godoc.org/github.com/icza/session
There are 3 key players in the package:
- Session is the (HTTP) session interface. We can use it to store and retrieve constant and variable attributes from it.
- Store is a session store interface which is responsible to store sessions and make them retrievable by their IDs at the server side.
- Manager is a session manager interface which is responsible to acquire a Session from an (incoming) HTTP request, and to add a Session to an HTTP response to let the client know about the session. A Manager has a backing Store which is responsible to manage Session values at server side.
Players of this package are represented by interfaces, and various implementations are provided for all these players.
You are not bound by the provided implementations, feel free to provide your own implementations for any of the players.
Usage can't be simpler than this. To get the current session associated with the http.Request:
To create a new session (e.g. on a successful login) and add it to an http.ResponseWriter (to let the client know about the session):
Let's see a more advanced session creation: let's provide a constant attribute (for the lifetime of the session) and an initial, variable attribute:
And to access these attributes and change value of "Count":
(Of course variable attributes can be added later on too with Session.SetAttr(), not just at session creation.)
To remove a session (e.g. on logout):
Check out the session demo application which shows all these in action:
https://github.com/icza/session/blob/master/session_demo/session_demo.go
The package provides support for Google App Engine (GAE) platform.
The documentation doesn't include it (due to the '+build appengine' build constraint), but here it is:
https://github.com/icza/session/blob/master/gae_memcache_store.go
The implementation stores sessions in the Memcache and also saves sessions in the Datastore as a backup
in case data would be removed from the Memcache. This behaviour is optional, Datastore can be disabled completely.
You can also choose whether saving to Datastore happens synchronously (in the same goroutine)
or asynchronously (in another goroutine), resulting in faster response times.
We can use NewMemcacheStore() and NewMemcacheStoreOptions() functions to create a session Store implementation
which stores sessions in GAE's Memcache. Important to note that since accessing the Memcache relies on
Appengine Context which is bound to an http.Request, the returned Store can only be used for the lifetime of a request!
Note that the Store will automatically "flush" sessions accessed from it when the Store is closed,
so it is very important to close the Store at the end of your request; this is usually done by closing
the session manager to which you passed the store (preferably with the defer statement).
So in each request handling we have to create a new session manager using a new Store, and we can use the session manager
to do session-related tasks, something like this:
Expired sessions are not automatically removed from the Datastore. To remove expired sessions, the package
provides a PurgeExpiredSessFromDSFunc() function which returns an http.HandlerFunc.
It is recommended to register the returned handler function to a path which then can be defined
as a cron job to be called periodically, e.g. in every 30 minutes or so (your choice).
As cron handlers may run up to 10 minutes, the returned handler will stop at 8 minutes
to complete safely even if there are more expired, undeleted sessions.
It can be registered like this:
Check out the GAE session demo application which shows how it can be used.
cron.yaml file of the demo shows how a cron job can be defined to purge expired sessions.
https://github.com/icza/session/blob/master/gae_session_demo/gae_session_demo.go
4 versions
Latest release: over 6 years ago
16 dependent packages
View more package details: https://packages.ecosyste.ms/registries/proxy.golang.org/packages/github.com/icza/session
View more repository details: http://repos.ecosyste.ms/hosts/GitHub/repositories/icza%2Fsession
Dependent Repos 21
werdes72/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 89.8 MB - Last synced: over 1 year ago - Pushed: over 1 year ago

eagle-dai/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 70.2 MB - Last synced: 11 months ago - Pushed: about 2 years ago

dennis-ge/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 87.9 MB - Last synced: almost 2 years ago - Pushed: almost 2 years ago


veichtj/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 80.2 MB - Last synced: about 2 years ago - Pushed: about 2 years ago

khlifi411/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 78.6 MB - Last synced: almost 2 years ago - Pushed: almost 2 years ago

ebensom/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 76.9 MB - Last synced: about 2 years ago - Pushed: about 2 years ago

thandayuthapani/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 77.3 MB - Last synced: about 1 year ago - Pushed: about 2 years ago

SamehMKhattab/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 78.2 MB - Last synced: about 2 years ago - Pushed: over 2 years ago

ystv/streamer
A better streaming solutionSize: 5.62 MB - Last synced: 2 months ago - Pushed: 2 months ago

chrkl/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 90.3 MB - Last synced: 8 days ago - Pushed: about 1 year ago

Cortey/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 108 MB - Last synced: about 1 year ago - Pushed: over 1 year ago

wozniakjan/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 86.5 MB - Last synced: about 1 year ago - Pushed: about 2 years ago

snipem/feeds2imap-go Fork of Gonzih/feeds2imap-go
Im bored, so im rewriting this thingSize: 140 KB - Last synced: 3 days ago - Pushed: over 2 years ago

moelsayed/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 85.7 MB - Last synced: almost 2 years ago - Pushed: over 2 years ago

pPrecel/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 91 MB - Last synced: 11 months ago - Pushed: about 1 year ago

mrCherry97/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 87.7 MB - Last synced: almost 2 years ago - Pushed: almost 2 years ago

PK85/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 72.4 MB - Last synced: about 2 years ago - Pushed: about 2 years ago

Pranav-SA/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 77.4 MB - Last synced: about 1 year ago - Pushed: about 1 year ago

mfaizanse/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 91.4 MB - Last synced: 11 months ago - Pushed: over 1 year ago

grischperl/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 93.8 MB - Last synced: over 1 year ago - Pushed: over 1 year ago

Prameesh-P/loginFormInGolang
This is login form..Using go and bootstrapSize: 2.93 KB - Last synced: about 2 years ago - Pushed: over 2 years ago

ajujacob88/golang-fundamentals
These are the fundamental topics in GO. Every beginner should try out these type of programs to basically understand the concepts of the GO.Size: 7.06 MB - Last synced: 11 months ago - Pushed: over 1 year ago

fynelabs/iot-blog-example
Small example showing a simple potential IoT application in Go.Size: 1.19 MB - Last synced: over 1 year ago - Pushed: over 2 years ago

mykter/rymdport Fork of Jacalz/rymdport
Cross-platform application for easy encrypted file, folder, and text sharing between devices.Size: 1.54 MB - Last synced: about 1 year ago - Pushed: almost 2 years ago

SecurityWorks/rymdport Fork of Jacalz/rymdport
Cross-platform application for easy encrypted file, folder, and text sharing between devices.Size: 1.92 MB - Last synced: 4 months ago - Pushed: 4 months ago

junlicn/selfupdate Fork of fynelabs/selfupdate
Build self-updating Golang programs to targetpath versionSize: 209 KB - Last synced: over 1 year ago - Pushed: over 1 year ago

CharlKlein/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 67.3 MB - Last synced: over 1 year ago - Pushed: about 4 years ago

fuskiid/selfupdate Fork of fynelabs/selfupdate
Build self-updating Golang programsSize: 208 KB - Last synced: 4 days ago - Pushed: almost 3 years ago

mvshao/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 88.3 MB - Last synced: 11 months ago - Pushed: about 1 year ago


kwiatekus/kyma Fork of kyma-project/kyma
A flexible and easy way to connect and extend enterprise applications in a cloud-native worldSize: 90.2 MB - Last synced: 11 months ago - Pushed: 11 months ago

Samige105/Assessment-framework Fork of yonush/pwrcost
Demo RESTapi in Go using the PostgreSQL databaseSize: 2.46 MB - Last synced: over 1 year ago - Pushed: over 1 year ago

ues-io/uesio
A new way to develop web applicationsSize: 84.9 MB - Last synced: 16 days ago - Pushed: 16 days ago

ratheeshkumar25/Rest-Api-Login-Admin
Login-Admin-JWT authSize: 52.7 KB - Last synced: about 1 year ago - Pushed: about 1 year ago

Athooh/Session-Management-Without-gorilla-in-Golang
login, logout wep application in golangSize: 4.88 KB - Last synced: about 1 year ago - Pushed: about 1 year ago


AgoCan/go-demo
平时写go的demo的时候,顺便记录Size: 10.7 MB - Last synced: about 2 years ago - Pushed: almost 4 years ago

icza/gaesession
Google App Engine (GAE) support for github.com/icza/sessionSize: 40 KB - Last synced: 2 months ago - Pushed: almost 2 years ago

KatherineMulder/ITPR6.518-Enterprise-Software-Development-Development
Katherine & Alex's AssignmentSize: 14 MB - Last synced: 10 months ago - Pushed: over 1 year ago

NongusStudios/ITPR6.518-Assesment-NoteSharingApp
Size: 10.3 MB - Last synced: 7 months ago - Pushed: 7 months ago
