https://github.com/nhas/session
A simple HTTP session manager
https://github.com/nhas/session
Last synced: 11 months ago
JSON representation
A simple HTTP session manager
- Host: GitHub
- URL: https://github.com/nhas/session
- Owner: NHAS
- Created: 2023-08-27T03:03:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-10T09:22:46.000Z (about 1 year ago)
- Last Synced: 2024-12-30T22:16:45.832Z (about 1 year ago)
- Language: Go
- Size: 26.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# session
A simple HTTP session manager. Got bored and needed to have a session manager that manages idle timeouts as well as longer max timeouts.
Example:
```go
type SessionEntry struct {
ArbitraryContent string
}
sessionManager = NewStore[SessionEntry]("session", time.Duration(IdleTimeDuration)*time.Second)
authorisedRoutes := http.NewServeMux()
authorisedRoutes.HandleFunc("/status", status)
authorisedRoutes.HandleFunc("/dashboard/", dashboard)
log.Fatal(http.ListenAndServe(addr, sessionManager.AuthorisationChecks(authorisedRoutes, nil)))
```
```go
_, data := sessionManager.GetSessionFromRequest(r)
if data == nil {
http.Error(w, "No", http.StatusUnauthorized)
return
}
```
```go
sessionKey := sessionManager.StartSession(w, r, currentSession, func(session SessionEntry) {
// Do something on session expiry
})
// Do stuff
sessionManager.DeleteSession(w,r)
```