restructure project

This commit is contained in:
Samuel Lorch 2023-03-26 18:50:18 +02:00
parent dd2db438f3
commit 2ca35d4461
46 changed files with 158 additions and 84 deletions

View file

@ -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}
}

View file

@ -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{