modulepackage
0.0.0-20241124222245-5e27e2e39187
Repository: https://github.com/nhas/session.git
Documentation: pkg.go.dev
# 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:
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)))
_, data := sessionManager.GetSessionFromRequest(r)
if data == nil {
http.Error(w, "No", http.StatusUnauthorized)
return
}
sessionKey := sessionManager.StartSession(w, r, currentSession, func(session SessionEntry) {
// Do something on session expiry
})
// Do stuff
sessionManager.DeleteSession(w,r)
# Functions
clearCookie will set a given cookie to blank value, expiring at the unix epoch.
No description provided by the author
Init will initialize the SessionStore object.
This should probably allow the user to specify.
# Structs
SessionStore holds the session data and settings.