mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 23:29:08 +00:00
restructure project
This commit is contained in:
parent
dd2db438f3
commit
2ca35d4461
46 changed files with 158 additions and 84 deletions
|
@ -1,10 +0,0 @@
|
|||
package session
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetCookie(value string, expires time.Time) *http.Cookie {
|
||||
return &http.Cookie{Name: SessionCookieName, HttpOnly: true, SameSite: http.SameSiteStrictMode, Value: value, Expires: expires}
|
||||
}
|
|
@ -13,6 +13,7 @@ type SessionKeyType string
|
|||
|
||||
const SessionKey SessionKeyType = "session"
|
||||
const SessionCookieName string = "session"
|
||||
const SessionLiveTime = 15
|
||||
|
||||
type Session struct {
|
||||
Username string
|
||||
|
@ -42,7 +43,7 @@ func ExtendSession(s *Session) {
|
|||
sessionsSync.Lock()
|
||||
defer sessionsSync.Unlock()
|
||||
if s != nil {
|
||||
s.Expires = time.Now().Add(time.Minute * 5)
|
||||
s.Expires = time.Now().Add(time.Minute * SessionLiveTime)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +61,7 @@ func GetSession(r *http.Request) (string, *Session) {
|
|||
|
||||
func GenerateSession(w http.ResponseWriter, username string) {
|
||||
id := uuid.New().String()
|
||||
expires := time.Now().Add(time.Minute * 5)
|
||||
expires := time.Now().Add(time.Minute * SessionLiveTime)
|
||||
sessionsSync.Lock()
|
||||
defer sessionsSync.Unlock()
|
||||
sessions[id] = &Session{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue