This commit is contained in:
jdl
2024-12-08 09:45:29 +01:00
parent 55a9bf9dc3
commit 03ff1aac80
60 changed files with 3165 additions and 2 deletions

33
hub/cookie.go Normal file
View File

@@ -0,0 +1,33 @@
package hub
import (
"net/http"
"time"
)
func (a *App) getCookie(r *http.Request, name string) string {
if c, err := r.Cookie(name); err == nil {
return c.Value
}
return ""
}
func (a *App) setCookie(w http.ResponseWriter, name, value string) {
http.SetCookie(w, &http.Cookie{
Name: name,
Value: value,
Path: "/",
Secure: a.secure,
SameSite: http.SameSiteStrictMode,
MaxAge: 86400 * 365 * 10,
})
}
func (a *App) deleteCookie(w http.ResponseWriter, name string) {
http.SetCookie(w, &http.Cookie{
Name: name,
Value: "",
Path: "/",
Expires: time.Unix(0, 0),
})
}