wip
This commit is contained in:
33
hub/cookie.go
Normal file
33
hub/cookie.go
Normal 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),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user