Skip to content

Latest commit

 

History

17 提交

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

仓库 files navigation

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 = 新建Store[SessionEntry]("session", time.Duration(IdleTimeDuration)*time.Second)

authorisedRoutes := http.新建ServeMux()
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)

关于

A simple HTTP session manager

Resources

Stars

2 stars

关注者

1 watching

复刻s

发布

Used by

贡献者

Languages