https://github.com/ymichael/sessions
Simple Server-Side Sessions for Goji
https://github.com/ymichael/sessions
Last synced: 8 months ago
JSON representation
Simple Server-Side Sessions for Goji
- Host: GitHub
- URL: https://github.com/ymichael/sessions
- Owner: ymichael
- License: mit
- Created: 2015-05-21T10:32:36.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-21T11:27:45.000Z (about 11 years ago)
- Last Synced: 2025-04-06T07:52:51.564Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 146 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sessions
Simple server-side sessions for [goji](goji.io).
```go
goji.Use(Sessions.Middleware())
```
## Dependencies
- [github.com/fzzy/radix](https://github.com/fzzy/radix) _If using RedisStore_.
## Usage
In-memory session store:
```go
var secret = "thisismysecret"
var inMemorySessionStore = sessions.MemoryStore{}
var Sessions = sessions.NewSessionOptions(secret, &inMemorySessionStore)
```
Using Redis (using fzzy/radix):
```go
var redisSessionStore = sessions.NewRedisStore("tcp", "localhost:6379")
var Sessions = sessions.NewSessionOptions(secret, redisSessionStore)
```
Use middleware:
```go
goji.Use(Sessions.Middleware())
```
Accessing session variable:
```go
func handler(c web.C, w http.ResponseWriter, r *http.Request) {
sessionObj := Sessions.GetSessionObject(&c)
// Regnerate session..
Sessions.RegenerateSession(&c)
// Delete session
Sessions.DeleteSession(&c)
}
```
See examples folder for full example.